Skip to content

Commit

Permalink
fix: improve error handling in casbinLinter
Browse files Browse the repository at this point in the history
  • Loading branch information
HashCookie committed Sep 1, 2024
1 parent 7e543b1 commit 3251a31
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions app/utils/casbinLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ export const casbinLinter = (view: EditorView): Diagnostic[] => {

const runTestError = getError();
if (runTestError) {
diagnostics.push({
from: 0,
to: view.state.doc.length,
severity: 'error',
message: `${runTestError}`,
});
const lineMatch = runTestError.match(/line (\d+)/);
if (lineMatch) {
const errorLine = parseInt(lineMatch[1], 10);
const line = view.state.doc.line(errorLine);
diagnostics.push({
from: line.from,
to: line.to,
severity: 'error',
message: runTestError,
});
} else {
diagnostics.push({
from: 0,
to: view.state.doc.length,
severity: 'error',
message: runTestError,
});
}
}

return diagnostics;
Expand Down

0 comments on commit 3251a31

Please sign in to comment.