[英]Error handling in extensions to visual studio code
有人可以指出 Visual Studio Code 擴展中錯誤處理的最佳實踐嗎?
我正在 TypeScript 中編寫一個擴展,它提供了一個調試器。 我想記錄意外行為,有時作為信息向用戶解釋 go 不正確,有時是為了創建調試線索,但肯定不會靜默失敗。 調試擴展時使用console.log
或console.error
出現在調試output中,但安裝擴展時找不到。 我是否必須專門為我的擴展打開一個 output 通道並在那里寫入所有內容? 我應該拋出showInformationMessage
和showErrorMessage
windows 嗎? 我應該只是拋出異常並希望代碼能做正確的事嗎?
在我的擴展中,我使用兩種方式進行反饋。 一個是 output 通道,用於處理我用於工作的外部進程產生的錯誤。
在您的激活方法中創建通道:
outputChannel = window.createOutputChannel("ANTLR4 Errors");
並在您有任何東西時將 output 推到它:
} catch (reason) {
outputChannel.appendLine("Cannot parse sentence generation config file:");
outputChannel.appendLine((reason as SyntaxError).message);
outputChannel.show(true);
return;
}
另一個是您已經考慮過的:
if (workspace.getConfiguration("antlr4.generation").mode === "none") {
void window.showErrorMessage("Interpreter data generation is disabled in the preferences (see " +
"'antlr4.generation'). Set this at least to 'internal' to enable debugging.");
return null;
}
這是我在擴展程序中創建的消息,用戶需要看到並認真對待。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.