You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
716 B
34 lines
716 B
4 weeks ago
|
class DBCError extends Error {
|
||
|
}
|
||
|
|
||
|
class CheckError extends DBCError {}
|
||
|
class SentinelError extends DBCError {}
|
||
|
class PreCondError extends DBCError {}
|
||
|
class PostCondError extends DBCError {}
|
||
|
|
||
|
export const check = (test, msg, err=CheckError) => {
|
||
|
if(!test) {
|
||
|
console.trace(msg);
|
||
|
throw new err(msg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const sentinel = (test) => {
|
||
|
check(test, "SENTINEL ERROR", SentinelError);
|
||
|
}
|
||
|
|
||
|
export const pre = (test_cb, msg) => {
|
||
|
check(test_cb(), `PRECOND ERROR: ${msg}`, PreCondError);
|
||
|
}
|
||
|
|
||
|
export const post = (test_cb, msg) => {
|
||
|
check(test_cb(), `POSTCOND ERROR: ${msg}`, PostCondError);
|
||
|
}
|
||
|
|
||
|
|
||
|
export default {
|
||
|
check, sentinel, pre, post,
|
||
|
CheckError, SentinelError, PreCondError,
|
||
|
PostCondError,
|
||
|
}
|