Skip to content

Commit

Permalink
feat(core): include function names in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Feb 21, 2022
1 parent 43b74d3 commit 2953155
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"lodash.topath": "^4.5.2",
"minimatch": "3.0.4",
"nimma": "0.1.8",
"pony-cause": "^1.0.0",
"simple-eval": "1.0.0",
"tslib": "^2.3.0"
},
Expand Down
21 changes: 16 additions & 5 deletions packages/core/src/runner/lintNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JsonPath } from '@stoplight/types';
import { decodeSegmentFragment, getClosestJsonPath, printPath, PrintStyle } from '@stoplight/spectral-runtime';
import { get } from 'lodash';
import { get, isError } from 'lodash';
import { ErrorWithCause } from 'pony-cause';

import { Document } from '../document';
import { IFunctionResult, IGivenNode, RulesetFunctionContext } from '../types';
Expand All @@ -24,10 +25,20 @@ export const lintNode = (context: IRunnerInternalContext, node: IGivenNode, rule
for (const target of targets) {
const path = target.path.length > 0 ? [...givenPath, ...target.path] : givenPath;

const targetResults = then.function(target.value, then.functionOptions ?? null, {
...fnContext,
path,
});
let targetResults;
try {
targetResults = then.function(target.value, then.functionOptions ?? null, {
...fnContext,
path,
});
} catch (e) {
throw new ErrorWithCause(
`Function "${then.function.name}" threw an exception${isError(e) ? `: ${e.message}` : ''}`,
{
cause: e,
},
);
}

if (targetResults === void 0) continue;

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,7 @@ __metadata:
minimatch: 3.0.4
nimma: 0.1.8
nock: ^13.1.0
pony-cause: ^1.0.0
simple-eval: 1.0.0
treeify: ^1.1.0
tslib: ^2.3.0
Expand Down

0 comments on commit 2953155

Please sign in to comment.