Skip to content

Commit

Permalink
fix: improve error handling in SSH connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Feb 12, 2025
1 parent 49a3589 commit 704f708
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/main/ipc-handlers/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export default (connections: Record<string, antares.Client>) => {
username: conn.sshUser,
password: conn.sshPass,
port: conn.sshPort ? conn.sshPort : 22,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : undefined,
passphrase: conn.sshPassphrase,
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : undefined
};
}

Expand All @@ -90,11 +90,12 @@ export default (connections: Record<string, antares.Client>) => {

return { status: 'success' };
}
catch (err) {
catch (error) {
clearInterval(abortChecker);

if (!isLocalAborted)
return { status: 'error', response: err.toString() };
if (error instanceof AggregateError)
throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
else if (!isLocalAborted)
return { status: 'error', response: error.toString() };
else
return { status: 'abort', response: 'Connection aborted' };
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/libs/clients/MySQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class MySQLClient extends BaseClient {
remotePort: this._params.port
});

dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host;
dbConfig.host = this._ssh.config[0].host;
dbConfig.port = tunnel.localPort;
}
catch (err) {
Expand Down Expand Up @@ -302,6 +302,8 @@ export class MySQLClient extends BaseClient {
await this.connect();
return this.getConnection(args, true);
}
else if (error instanceof AggregateError)
throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
else
throw new Error(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/libs/clients/PostgreSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class PostgreSQLClient extends BaseClient {
remotePort: this._params.port
});

dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host;
dbConfig.host = this._ssh.config[0].host;
dbConfig.port = tunnel.localPort;
}
catch (err) {
Expand Down
14 changes: 12 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ app.on('ready', async () => {
// mainWindow.webContents.openDevTools();

process.on('uncaughtException', error => {
mainWindow.webContents.send('unhandled-exception', error);
if (error instanceof AggregateError) {
for (const e of error.errors)
mainWindow.webContents.send('unhandled-exception', e);
}
else
mainWindow.webContents.send('unhandled-exception', error);
});

process.on('unhandledRejection', error => {
mainWindow.webContents.send('unhandled-exception', error);
if (error instanceof AggregateError) {
for (const e of error.errors)
mainWindow.webContents.send('unhandled-exception', e);
}
else
mainWindow.webContents.send('unhandled-exception', error);
});
});

Expand Down

0 comments on commit 704f708

Please sign in to comment.