MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / findErrorLocation

Function findErrorLocation

src/kernels/execution/helpers.ts:864–890  ·  view source on GitHub ↗
(traceback: string[], cell: NotebookCell)

Source from the content-addressed store, hash-verified

862}
863
864export function findErrorLocation(traceback: string[], cell: NotebookCell) {
865 const cellRegex = /Cell\s+In\s*\[(?<executionCount>\d+)\],\s*line (?<lineNumber>\d+).*/;
866 // older versions of IPython ~8.3.0
867 const inputRegex = /Input\s+?In\s*\[(?<executionCount>\d+)\][^<]*<cell line:\s?(?<lineNumber>\d+)>.*/;
868 let lineNumber: number | undefined = undefined;
869 for (const line of traceback) {
870 const cleanLine = removeAnsiEscapeCodes(line);
871 const lineMatch = cellRegex.exec(cleanLine) ?? inputRegex.exec(cleanLine);
872 if (lineMatch && lineMatch.groups) {
873 lineNumber = parseInt(lineMatch.groups['lineNumber']);
874 break;
875 }
876 }
877
878 let range: Range | undefined = undefined;
879 if (lineNumber && lineNumber > 0 && lineNumber <= cell.document.lineCount) {
880 const line = cell.document.lineAt(lineNumber - 1);
881 const end = line.text.split('#')[0].trimEnd().length;
882
883 range = new Range(
884 new Position(line.lineNumber, line.firstNonWhitespaceCharacterIndex),
885 new Position(line.lineNumber, end)
886 );
887 }
888
889 return range;
890}

Callers 2

handleErrorMethod · 0.90

Calls 3

removeAnsiEscapeCodesFunction · 0.85
lineAtMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected