shapez/src/js/core/assert.js

27 lines
765 B
JavaScript
Raw Normal View History

2020-05-09 16:45:23 +02:00
import { createLogger } from "./logging";
const logger = createLogger("assert");
let assertionErrorShown = false;
function initAssert() {
/**
* Expects a given condition to be true
* @param {Boolean} condition
* @param {...String} failureMessage
*/
// @ts-ignore
window.assert = function (condition, ...failureMessage) {
if (!condition) {
logger.error("assertion failed:", ...failureMessage);
if (!assertionErrorShown) {
// alert("Assertion failed (the game will try to continue to run): \n\n" + failureMessage);
assertionErrorShown = true;
}
throw new Error("AssertionError: " + failureMessage.join(" "));
}
};
}
initAssert();