Skip to content

Commit

Permalink
feat: print also data and keys on slangroom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino committed Jun 24, 2024
1 parent 6bc0612 commit 82ae8df
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/core/src/slangroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Slangroom {
const exec = this.#plugins.get(ast.key);
if (!exec) return thorwErrors( [{message: new Error('no statements matched'), lineNo}], contract);
const res = await exec(new PluginContextImpl(ast));
if (!res.ok) return thorwErrors( [{message: res.error, lineNo}], contract);
if (!res.ok) return thorwErrors( [{message: res.error, lineNo}], contract, paramsGiven);
if (res.ok && ast.into) paramsGiven.data[ast.into] = res.value;
}

Expand All @@ -115,7 +115,7 @@ export class Slangroom {
const exec = this.#plugins.get(ast.key);
if (!exec) return thorwErrors( [{message: new Error('no statements matched'), lineNo}], contract);
const res = await exec(new PluginContextImpl(ast));
if (!res.ok) return thorwErrors( [{message: res.error, lineNo}], contract);
if (!res.ok) return thorwErrors( [{message: res.error, lineNo}], contract, paramsThen);
if (res.ok && ast.into) paramsThen.data[ast.into] = res.value;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ const requirifyZenParams = (params?: Partial<ZenParams>): Required<ZenParams> =>
* @param error {message, lineNo, ?start, ?end}
* @param contract {string}
*/
const thorwErrors = (errorArray: GenericError[], contract: string) => {
const thorwErrors = (errorArray: GenericError[], contract: string, params?: ZenParams) => {
const contractLines = contract.split('\n');
const lineNumber = errorArray[0]!.lineNo;
const initialWS = contractLines[lineNumber-1]!.match(/^[\s]+/) || [''];
Expand All @@ -171,5 +171,10 @@ const thorwErrors = (errorArray: GenericError[], contract: string) => {
for (let err of errorArray) {
e = e.concat('\n' + err.message + '\n');
}
if(params) {
delete params.extra;
delete params.conf;
e = e.concat('\n' + 'Heap:\n' + JSON.stringify(params, null, 4) + '\n');
}
throw new Error(e);
}

0 comments on commit 82ae8df

Please sign in to comment.