Skip to content

Commit 704f708

Browse files
committed
fix: improve error handling in SSH connection
1 parent 49a3589 commit 704f708

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/main/ipc-handlers/connection.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export default (connections: Record<string, antares.Client>) => {
6464
username: conn.sshUser,
6565
password: conn.sshPass,
6666
port: conn.sshPort ? conn.sshPort : 22,
67-
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null,
67+
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : undefined,
6868
passphrase: conn.sshPassphrase,
69-
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null
69+
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : undefined
7070
};
7171
}
7272

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

9191
return { status: 'success' };
9292
}
93-
catch (err) {
93+
catch (error) {
9494
clearInterval(abortChecker);
95-
96-
if (!isLocalAborted)
97-
return { status: 'error', response: err.toString() };
95+
if (error instanceof AggregateError)
96+
throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
97+
else if (!isLocalAborted)
98+
return { status: 'error', response: error.toString() };
9899
else
99100
return { status: 'abort', response: 'Connection aborted' };
100101
}

src/main/libs/clients/MySQLClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class MySQLClient extends BaseClient {
173173
remotePort: this._params.port
174174
});
175175

176-
dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host;
176+
dbConfig.host = this._ssh.config[0].host;
177177
dbConfig.port = tunnel.localPort;
178178
}
179179
catch (err) {
@@ -302,6 +302,8 @@ export class MySQLClient extends BaseClient {
302302
await this.connect();
303303
return this.getConnection(args, true);
304304
}
305+
else if (error instanceof AggregateError)
306+
throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
305307
else
306308
throw new Error(error.message);
307309
}

src/main/libs/clients/PostgreSQLClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class PostgreSQLClient extends BaseClient {
179179
remotePort: this._params.port
180180
});
181181

182-
dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host;
182+
dbConfig.host = this._ssh.config[0].host;
183183
dbConfig.port = tunnel.localPort;
184184
}
185185
catch (err) {

src/main/main.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,21 @@ app.on('ready', async () => {
132132
// mainWindow.webContents.openDevTools();
133133

134134
process.on('uncaughtException', error => {
135-
mainWindow.webContents.send('unhandled-exception', error);
135+
if (error instanceof AggregateError) {
136+
for (const e of error.errors)
137+
mainWindow.webContents.send('unhandled-exception', e);
138+
}
139+
else
140+
mainWindow.webContents.send('unhandled-exception', error);
136141
});
137142

138143
process.on('unhandledRejection', error => {
139-
mainWindow.webContents.send('unhandled-exception', error);
144+
if (error instanceof AggregateError) {
145+
for (const e of error.errors)
146+
mainWindow.webContents.send('unhandled-exception', e);
147+
}
148+
else
149+
mainWindow.webContents.send('unhandled-exception', error);
140150
});
141151
});
142152

0 commit comments

Comments
 (0)