Skip to content

Commit

Permalink
Log errors to output channel instead of a toast message (#46)
Browse files Browse the repository at this point in the history
* Log errors to output channel instead of a toast message

* Update CHANGELOG.md

* Check last call to output channel
  • Loading branch information
gediminasz committed Nov 5, 2023
1 parent a50719b commit c261847
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Unreleased

- `readtags` and `ctags` execution errors are now logged to "Ctags Companion" output channel instead of toast notifications.

## 2023.10.2

- Removed reference to no longer functional reindex command.
Expand Down
8 changes: 5 additions & 3 deletions src/__mocks__/vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const workspace = {
console.assert(workspace.asRelativePath({ fsPath: "/test/foo" }) == "foo");
console.assert(workspace.asRelativePath({ fsPath: "/elsewhere/bar" }) == "/elsewhere/bar");

const mockOutputChannel = {
appendLine: jest.fn(),
};

const window = {
showErrorMessage: jest.fn(),
createOutputChannel: () => ({
appendLine() { }
})
createOutputChannel: () => mockOutputChannel
};

function Position(line, character) {
Expand Down
7 changes: 4 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ function findField(tags, prefix) {
return tag && tag.substring(prefix.length);
}

const outputChannel = vscode.window.createOutputChannel(EXTENSION_NAME);

function wrapExec(exec, platform = process.platform) {
const outputChannel = vscode.window.createOutputChannel(EXTENSION_NAME);
return async (command, options) => {
try {
if (platform === "win32") {
// Use PowerShell on Windows because Command Prompt does not support single quotes
options = {...options, shell: "powershell.exe"}
options = { ...options, shell: "powershell.exe" };
}

outputChannel.appendLine(`${command} ${JSON.stringify(options)}`);
Expand All @@ -114,7 +115,7 @@ function wrapExec(exec, platform = process.platform) {
const output = stdout.trim();
return output ? output.split('\n') : [];
} catch ({ message }) {
vscode.window.showErrorMessage(`${EXTENSION_NAME}: ${message}`);
outputChannel.appendLine(message);
return [];
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ describe('wrapExec', () => {
};

const result = await wrapExec(exec)();

expect(result).toEqual([]);
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith("Ctags Companion: epic fail");

const outputChannel = vscode.window.createOutputChannel();
expect(outputChannel.appendLine).toHaveBeenLastCalledWith("epic fail");
});

it.each([
Expand Down

0 comments on commit c261847

Please sign in to comment.