2022-02-15 20:33:31 -07:00
|
|
|
'use strict';
|
|
|
|
|
2022-09-20 15:02:09 -06:00
|
|
|
class AssertionError extends Error {
|
|
|
|
constructor(...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) {
|
|
|
|
Error.captureStackTrace(this, AssertionError);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.name = 'AssertionError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 00:33:16 -07:00
|
|
|
function assert(value, message) {
|
|
|
|
if (!value) {
|
2022-09-20 15:02:09 -06:00
|
|
|
const error = new AssertionError(message || `expected ${value} to be truthy`);
|
|
|
|
//console.error(error);
|
|
|
|
throw error;
|
2022-02-15 00:33:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = assert;
|