Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log errors to output channel instead of a toast message #46

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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