Skip to content

Commit 0dd4f2e

Browse files
committed
fix: proper error messages for exceptions
Use .name and .message for exceptions.
1 parent d31a159 commit 0dd4f2e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/extension/fbaEditor.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
117117
}
118118
}
119119
} catch (error) {
120-
console.log(`fishbone: extension ${value.id} throws: ${error}`);
120+
console.log(`fishbone: extension ${value.id} throws: ${error.name}:${error.message}`);
121121
}
122122
}
123123
});
@@ -233,8 +233,8 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
233233
FBAEditorProvider.updateTextDocument(docData, document, { fishbone: e.data, title: e.title, attributes: e.attributes }), 1);
234234
*/
235235
} catch (e) {
236-
console.error(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${JSON.stringify(e)}.`);
237-
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${JSON.stringify(e)}.`);
236+
console.error(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${e.name}:${e.message}.`);
237+
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${e.name}:${e.message}.`);
238238
}
239239
break;
240240
case 'sAr':
@@ -279,7 +279,7 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
279279
const json = JSON.parse(result.body);
280280
webviewPanel.webview.postMessage({ type: e.type, res: json, id: e.id });
281281
}).catch(err => {
282-
webviewPanel.webview.postMessage({ type: e.type, res: { errors: [`request failed with err=${err}`] }, id: e.id });
282+
webviewPanel.webview.postMessage({ type: e.type, res: { errors: [`request failed with err=${err.name}:${err.message}`] }, id: e.id });
283283
});
284284
}
285285
}
@@ -414,7 +414,7 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
414414
yamlObj = {};
415415
}
416416
} catch (e) {
417-
console.error('Could not get document as json. Content is not valid yaml e= ' + e);
417+
console.error(`Could not get document as json. Content is not valid yaml e=${e.name}:${e.message}`);
418418
}
419419

420420
// only 'title', 'attributes' and 'fishbone' are updated for now. keep the rest:
@@ -490,7 +490,7 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
490490
};
491491
}
492492
} catch (e) {
493-
console.error(`opening file failed with err:'${e}'`);
493+
console.error(`opening file failed with err:'${e.name}:${e.message}'`);
494494
}
495495
}
496496
return null; // delete the import rc
@@ -532,8 +532,8 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
532532
};
533533
}
534534
} catch (e) {
535-
console.warn(`re-importing file '${rc.relPath}' failed due to:'${e}'`);
536-
vscode.window.showWarningMessage(`re-importing file '${rc.relPath} failed due to:'${e}'`);
535+
console.warn(`re-importing file '${rc.relPath}' failed due to:'${e.name}:${e.message}'`);
536+
vscode.window.showWarningMessage(`re-importing file '${rc.relPath} failed due to:'${e.name}:${e.message}'`);
537537
}
538538
console.log('reimport done/failed');
539539
} else {
@@ -564,8 +564,8 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
564564
} catch (e) {
565565
// need to remove this one from the queue
566566
docData.editsPending.shift();
567-
console.error(`storing as YAML failed. Error=${e}`);
568-
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Storing as YAML failed. Error=${e}`);
567+
console.error(`storing as YAML failed. Error=${e.name}:${e.message}`);
568+
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Storing as YAML failed. Error=${e.name}:${e.message}`);
569569
return false;
570570
}
571571
console.warn(`FBAEditorProvider.processEditsPendingQueue will apply edit with size=${edit.size}, editsPending.length=${docData.editsPending.length} version=${document.version}`);
@@ -706,10 +706,9 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
706706

707707
return { attributes: yamlObj?.attributes, fishbone: yamlObj.fishbone, title: yamlObj.title || '<please add title to .fba>' };
708708
} catch (e) {
709-
vscode.window.showErrorMessage(`Fishbone: Could not get document as yaml. Content is not valid yaml. Error= ${e}`);
710-
throw new Error('Could not get document as yaml. Content is not valid yaml e= ' + e);
709+
vscode.window.showErrorMessage(`Fishbone: Could not get document as yaml. Content is not valid yaml. Error= ${e.name}:${e.message}`);
710+
throw new Error(`Fishbone: Could not get document as yaml. Content is not valid yaml. Error= ${e.name}:${e.message}`);
711711
}
712-
return { title: '<error>' };
713712
}
714713

715714
/**

0 commit comments

Comments
 (0)