Skip to content

Instantly share code, notes, and snippets.

@roine
Created May 22, 2024 01:18
Show Gist options
  • Save roine/0a5829cc4ff58fcfb259dd1ab63d02cc to your computer and use it in GitHub Desktop.
Save roine/0a5829cc4ff58fcfb259dd1ab63d02cc to your computer and use it in GitHub Desktop.
Custom version of invariant, removes the invariant frame from the call stack
function invariant(condition, message, a, b, c, d, e, f) {
if (!condition) {
var error;
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
message.replace(/%s/g, function () {
return args[argIndex++];
})
);
error.name = "Invariant Violation";
// remove this frame from the stack
var arr = error.stack.split("\n");
error.stack = [arr[0]].concat(arr.slice(2)).join("\n");
throw error;
}
return condition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment