This is the template project that's checked out and configured when you run the bando-up command from ljsthw-bandolier. This is where the code really lives.
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.
bandolier-template/client/assert.js

36 lines
1.1 KiB

import { log } from "./logging.js";
/* I can't believe I have to write this just so I can use the assert that should be standard in every javascript. */
class AssertionError extends Error {
/* This is from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
* which claims you have to do this weird stuff to make your error actually work.
*/
constructor(foo = 'bar', ...params) {
// Pass remaining arguments (including vendor specific ones) to parent constructor
super(...params);
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
// this "only on V8" is managed by the Error.captureStackTrace test above
Error.captureStackTrace(this, AssertionError);
}
this.name = 'AssertionError';
// Custom debugging information
this.foo = foo;
this.date = new Date();
}
}
const assert = (test, message) => {
log.assert(test, message);
if(!test) {
throw new AssertionError(message);
}
}
export default assert;