@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
74 lines (70 loc) • 2.46 kB
JavaScript
;
/** use this to ensure that all cases are covered in case of a selection */
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertUnreachable = assertUnreachable;
exports.isNotUndefined = isNotUndefined;
exports.isUndefined = isUndefined;
exports.isNotNull = isNotNull;
exports.guard = guard;
/* v8 ignore next */
const version_1 = require("./version");
function assertUnreachable(x) {
throw new Error(`Unexpected object: ${JSON.stringify(x)}`);
}
function isNotUndefined(x) {
return x !== undefined;
}
function isUndefined(x) {
return x === undefined;
}
function isNotNull(x) {
return x !== null;
}
function prepareStack(stack) {
if (!stack) {
return 'No stack trace available';
}
// remove the first line which is the error message
let lines = stack.split('\n');
lines.shift();
lines.shift();
lines.shift();
// clip over 8
if (lines.length > 8) {
lines = [...lines.slice(0, 3),
'...', ...lines.slice(lines.length - 5)];
}
return lines.map(l => l.replaceAll(/\(\/.*(src|test)/g, '(<>/$1')).join('\n');
}
function getGuardIssueUrl(message) {
const body = encodeURIComponent(`<!-- Please describe your issue in more detail below! -->
<!-- Automatically generated issue metadata, please do not edit or delete content below this line -->
---
flowR version: ${(0, version_1.flowrVersion)().toString()}
node version: ${process.version}
node arch: ${process.arch}
node platform: ${process.platform}
message: \`${message}\`
stack trace:\n\`\`\`\n${prepareStack(new Error().stack)}\n\`\`\`
---
`).replaceAll('(', '%28').replaceAll(')', '%29').replaceAll('-', '%2D');
return `https://github.com/flowr-analysis/flowr/issues/new?body=${body}`;
}
class GuardError extends Error {
constructor(message) {
super(message + '\n Report a Bug: ' + getGuardIssueUrl(message));
this.name = 'GuardError';
}
}
/**
* @param assertion - will be asserted
* @param message - if a string, we will use it as the error message, if it is a function, we will call it to produce the error message (can be used to avoid costly message generations)
* @throws GuardError - if the assertion fails
*/
function guard(assertion, message = 'Assertion failed') {
/* v8 ignore next 3 */
if (!assertion) {
throw new GuardError(typeof message === 'string' ? message : message());
}
}
//# sourceMappingURL=assert.js.map