Skip to content

Commit 6be82ef

Browse files
Copilotgarrytrinder
andcommitted
Fix failing tests: wrap logger calls in try-catch for closed channel
Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
1 parent 6b5f43b commit 6be82ef

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/logger.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,43 @@ function getLogger(): vscode.LogOutputChannel | undefined {
2828
* Log a trace-level message.
2929
*/
3030
export function trace(message: string, ...args: unknown[]): void {
31-
getLogger()?.trace(message, ...args);
31+
try {
32+
getLogger()?.trace(message, ...args);
33+
} catch { /* channel may be closed */ }
3234
}
3335

3436
/**
3537
* Log a debug-level message.
3638
*/
3739
export function debug(message: string, ...args: unknown[]): void {
38-
getLogger()?.debug(message, ...args);
40+
try {
41+
getLogger()?.debug(message, ...args);
42+
} catch { /* channel may be closed */ }
3943
}
4044

4145
/**
4246
* Log an info-level message.
4347
*/
4448
export function info(message: string, ...args: unknown[]): void {
45-
getLogger()?.info(message, ...args);
49+
try {
50+
getLogger()?.info(message, ...args);
51+
} catch { /* channel may be closed */ }
4652
}
4753

4854
/**
4955
* Log a warning-level message.
5056
*/
5157
export function warn(message: string, ...args: unknown[]): void {
52-
getLogger()?.warn(message, ...args);
58+
try {
59+
getLogger()?.warn(message, ...args);
60+
} catch { /* channel may be closed */ }
5361
}
5462

5563
/**
5664
* Log an error-level message.
5765
*/
5866
export function error(message: string, ...args: unknown[]): void {
59-
getLogger()?.error(message, ...args);
67+
try {
68+
getLogger()?.error(message, ...args);
69+
} catch { /* channel may be closed */ }
6070
}

0 commit comments

Comments
 (0)