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

Function formatErrors

src/platform/logging/index.ts:128–190  ·  view source on GitHub ↗
(...args: Arguments)

Source from the content-addressed store, hash-verified

126}
127
128function formatErrors(...args: Arguments) {
129 // Format the error message, if showing verbose then include all of the error stack & other details.
130 const formatError = globalLoggingLevel <= LogLevel.Debug ? false : true;
131 if (!formatError) {
132 return args;
133 }
134 return args.map((arg) => {
135 if (!(arg instanceof Error)) {
136 return arg;
137 }
138 // Only format errors raised by Jupyter extension.
139 if (!('isJupyterError' in arg)) {
140 return arg;
141 }
142 const info: string[] = [`${arg.name}: ${arg.message}`.trim()];
143 if (
144 'kernelConnectionMetadata' in arg &&
145 arg.kernelConnectionMetadata &&
146 typeof arg.kernelConnectionMetadata === 'object' &&
147 'id' in arg.kernelConnectionMetadata
148 ) {
149 info.push(`Kernel Id = ${arg.kernelConnectionMetadata.id}`);
150 if (
151 'interpreter' in arg.kernelConnectionMetadata &&
152 arg.kernelConnectionMetadata.interpreter &&
153 typeof arg.kernelConnectionMetadata.interpreter === 'object' &&
154 'id' in arg.kernelConnectionMetadata.interpreter &&
155 typeof arg.kernelConnectionMetadata.interpreter.id === 'string'
156 ) {
157 info.push(`Interpreter Id = ${getDisplayPath(arg.kernelConnectionMetadata.interpreter.id)}`);
158 }
159 }
160 if (arg.stack) {
161 const stack = splitLines(arg.stack);
162 const firstStackLine = stack.find((l) => l.indexOf('at ') === 0);
163 if (stack.length === 1) {
164 //
165 } else if (stack.length === 1) {
166 info.push(stack[0]);
167 } else if (stack.length > 1 && firstStackLine?.length) {
168 info.push(firstStackLine);
169 } else {
170 info.push(stack[0]);
171 }
172 }
173 const propertiesToIgnore = [
174 'stack',
175 'message',
176 'name',
177 'kernelConnectionMetadata',
178 'category',
179 'exitCode',
180 'isJupyterError'
181 ];
182 Object.keys(arg)
183 .filter((key) => propertiesToIgnore.indexOf(key) === -1)
184 .forEach((key) => info.push(`${key} = ${String((arg as any)[key]).trim()}`));
185 return info

Callers 2

logErrorFunction · 0.85
logWarningFunction · 0.85

Calls 8

getDisplayPathFunction · 0.90
splitLinesFunction · 0.90
mapMethod · 0.80
filterMethod · 0.80
joinMethod · 0.80
pushMethod · 0.65
forEachMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected