Skip to content

Commit

Permalink
Disambiguate tunnel connection is disposed error (microsoft#411)
Browse files Browse the repository at this point in the history
* Disambiguate Tunnel connection is disposed error

* update package version

* update from CR comments
  • Loading branch information
jramsay authored Mar 5, 2024
1 parent 10c2848 commit 2d16ff1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ts/src/connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.23",
"@microsoft/dev-tunnels-management": ">1.1.23",
"@microsoft/dev-tunnels-contracts": ">1.1.24",
"@microsoft/dev-tunnels-management": ">1.1.24",
"@microsoft/dev-tunnels-ssh": "^3.11.36",
"@microsoft/dev-tunnels-ssh-tcp": "^3.11.36",
"uuid": "^3.3.3",
Expand Down
10 changes: 7 additions & 3 deletions ts/src/connections/tunnelConnectionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TunnelConnectionBase implements TunnelConnection {
*/
protected set connectionStatus(value: ConnectionStatus) {
if (this.isDisposed && value !== ConnectionStatus.Disconnected) {
this.throwIfDisposed();
this.throwIfDisposed(`ConnectionStatus: ${value}`);
}

if (value === ConnectionStatus.RefreshingTunnelAccessToken && this.status !== ConnectionStatus.Connecting) {
Expand Down Expand Up @@ -168,9 +168,13 @@ export class TunnelConnectionBase implements TunnelConnection {
/**
* Throws CancellationError if the tunnel connection is disposed.
*/
protected throwIfDisposed() {
protected throwIfDisposed(message: string, stack?: string) {
if (this.isDisposed) {
throw new ObjectDisposedError('The tunnel connection is disposed.');
const error = new ObjectDisposedError(`The tunnel connection is disposed. ${message}`);
if (stack) {
error.stack = stack;
}
throw error;
}
}
}
2 changes: 1 addition & 1 deletion ts/src/connections/tunnelConnectionSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export class TunnelConnectionSession extends TunnelConnectionBase implements Tun
await this.connector.connectSession(isReconnect, options, cancellation);
} catch (e) {
if (e instanceof CancellationError) {
this.throwIfDisposed();
this.throwIfDisposed(`CancelationError: ${e.message}`, e.stack);
}
throw e;
} finally {
Expand Down
2 changes: 1 addition & 1 deletion ts/src/management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.23",
"@microsoft/dev-tunnels-contracts": ">1.1.24",
"axios": "^1.6.6"
}
}

0 comments on commit 2d16ff1

Please sign in to comment.