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, }