Skip to content

Commit ec791e3

Browse files
committed
Display connection error message + add detail in output
Signed-off-by: Seb Julliand <[email protected]>
1 parent b0b1f04 commit ec791e3

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

src/api/IBMi.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as node_ssh from "node-ssh";
44
import os from "os";
55
import path, { parse as parsePath } from 'path';
66
import { EventEmitter } from 'stream';
7-
import { EditorPath } from './types';
87
import { CompileTools } from "./CompileTools";
98
import IBMiContent from "./IBMiContent";
109
import { Tools } from './Tools';
@@ -16,9 +15,9 @@ import * as configVars from './configVars';
1615
import { DebugConfiguration } from "./configuration/DebugConfiguration";
1716
import { ConnectionManager } from './configuration/config/ConnectionManager';
1817
import { ConnectionConfig, RemoteConfigFile } from './configuration/config/types';
19-
import { CachedServerSettings, CodeForIStorage } from './configuration/storage/CodeForIStorage';
20-
import { AspInfo, CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, WrapResult } from './types';
2118
import { ConfigFile } from './configuration/serverFile';
19+
import { CachedServerSettings, CodeForIStorage } from './configuration/storage/CodeForIStorage';
20+
import { AspInfo, CommandData, CommandResult, ConnectionData, EditorPath, IBMiMember, RemoteCommand, WrapResult } from './types';
2221

2322
export interface MemberParts extends IBMiMember {
2423
basename: string
@@ -28,8 +27,9 @@ export type ConnectionMessageType = 'info' | 'warning' | 'error';
2827
export type ConnectionErrorCode = `shell_config` | `home_directory_creation` | `QCPTOIMPF_exists` | `QCPFRMIMPF_exists` | `default_not_bash` | `invalid_bashrc` | `invalid_temp_lib` | `no_auto_conv_ebcdic` | `not_loaded_debug_config` | `no_sql_runner` | `ccsid_warning`;
2928

3029
export interface ConnectionResult {
31-
success: boolean,
32-
errorCodes?: ConnectionErrorCode[],
30+
success: boolean
31+
error?: string
32+
errorCodes?: ConnectionErrorCode[]
3333
}
3434

3535
const remoteApps = [ // All names MUST also be defined as key in 'remoteFeatures' below!!
@@ -122,7 +122,7 @@ export default class IBMi {
122122
* the root of the IFS, thus why we store it.
123123
*/
124124
private iAspInfo: AspInfo[] = [];
125-
private currentAsp: string|undefined;
125+
private currentAsp: string | undefined;
126126
private libraryAsps = new Map<string, number>();
127127

128128
/**
@@ -990,16 +990,22 @@ export default class IBMi {
990990

991991
let error = e.message;
992992
if (e.code === "ENOTFOUND") {
993-
error = `Host is unreachable. Check the connection's hostname/IP address.`;
993+
error = `host is unreachable. Check the connection's hostname/IP address.`;
994994
}
995995
else if (e.code === "ECONNREFUSED") {
996-
error = `Port ${connectionObject.port} is unreachable. Check the connection's port number or run command STRTCPSVR SERVER(*SSHD) on the host.`
996+
error = `port ${connectionObject.port} is unreachable. Check the connection's port number or run command STRTCPSVR SERVER(*SSHD) on the host.`
997997
}
998998
else if (e.level === "client-authentication") {
999-
error = `Check your credentials${e.message ? ` (${e.message})` : ''}.`;
999+
error = `check your credentials${e.message ? ` (${e.message})` : ''}.`;
1000+
}
1001+
1002+
this.appendOutput(`${JSON.stringify(e)}`);
1003+
if (typeof e.stack === "string") {
1004+
this.appendOutput(`\n\n${e.stack}`);
10001005
}
10011006

10021007
return {
1008+
error,
10031009
success: false
10041010
};
10051011
}
@@ -1523,7 +1529,7 @@ export default class IBMi {
15231529
return this.remoteFeatures[`startDebugService.sh`] !== undefined;
15241530
}
15251531

1526-
private async getUserProfileAsp(): Promise<string|undefined> {
1532+
private async getUserProfileAsp(): Promise<string | undefined> {
15271533
const [currentRdb] = await this.runSQL(`values current_server`);
15281534

15291535
if (currentRdb) {
@@ -1541,8 +1547,8 @@ export default class IBMi {
15411547
return this.iAspInfo;
15421548
}
15431549

1544-
getIAspDetail(by: string|number) {
1545-
let asp: AspInfo|undefined;
1550+
getIAspDetail(by: string | number) {
1551+
let asp: AspInfo | undefined;
15461552
if (typeof by === 'string') {
15471553
asp = this.iAspInfo.find(asp => asp.name === by);
15481554
} else {
@@ -1554,14 +1560,14 @@ export default class IBMi {
15541560
}
15551561
}
15561562

1557-
getIAspName(by: string|number): string|undefined {
1563+
getIAspName(by: string | number): string | undefined {
15581564
return this.getIAspDetail(by)?.name;
15591565
}
15601566

15611567
getCurrentIAspName() {
15621568
return this.currentAsp;
15631569
}
1564-
async lookupLibraryIAsp(library: string): Promise<string|undefined> {
1570+
async lookupLibraryIAsp(library: string): Promise<string | undefined> {
15651571
library = this.upperCaseName(library);
15661572
let foundNumber = this.libraryAsps.get(library);
15671573

src/api/tests/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export async function newConnection(reloadSettings?: boolean) {
102102
}
103103

104104
if (!result.success) {
105-
throw new Error(`Failed to connect to IBMi`);
105+
throw new Error(`Failed to connect to IBMi${result.error ? `: ${result.error}` : '!'}`);
106106
}
107107

108108
return conn;

src/commands/connection.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { commands, Disposable, ExtensionContext, window } from "vscode";
2+
import { ConnectionResult } from "../api/IBMi";
3+
import { setStoredPassword } from "../config/passwords";
24
import Instance from "../Instance";
3-
import { ConnectionData } from "../typings";
45
import { safeDisconnect } from "../instantiate";
5-
import { setStoredPassword } from "../config/passwords";
6+
import { ConnectionData } from "../typings";
67

78
export function registerConnectionCommands(context: ExtensionContext, instance: Instance): Disposable[] {
89

910
return [
1011
commands.registerCommand(`code-for-ibmi.connectDirect`,
11-
async (connectionData: ConnectionData, reloadSettings = false, savePassword = false): Promise<boolean> => {
12+
async (connectionData: ConnectionData, reloadSettings = false, savePassword = false): Promise<ConnectionResult | undefined> => {
1213
const existingConnection = instance.getConnection();
1314

1415
if (existingConnection) {
15-
return false;
16+
return;
1617
}
1718

1819
if (savePassword && connectionData.password) {
1920
await setStoredPassword(context, connectionData.name, connectionData.password);
2021
}
2122

22-
return (await instance.connect({data: connectionData, reloadServerSettings: reloadSettings})).success;
23+
return (await instance.connect({ data: connectionData, reloadServerSettings: reloadSettings }));
2324
}
2425
),
2526
commands.registerCommand(`code-for-ibmi.disconnect`, async (silent?: boolean) => {

src/webviews/login/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import vscode, { l10n, ThemeIcon } from "vscode";
2-
import { CustomUI, Section } from "../CustomUI";
2+
import IBMi from "../../api/IBMi";
33
import { Tools } from "../../api/Tools";
4+
import { deleteStoredPassword, getStoredPassword, setStoredPassword } from "../../config/passwords";
45
import { instance, safeDisconnect } from "../../instantiate";
56
import { ConnectionData } from '../../typings';
6-
import IBMi from "../../api/IBMi";
7-
import { deleteStoredPassword, getStoredPassword, setStoredPassword } from "../../config/passwords";
7+
import { CustomUI, Section } from "../CustomUI";
88

99
type NewLoginSettings = ConnectionData & {
1010
savePassword: boolean
@@ -120,7 +120,7 @@ export class Login {
120120
}
121121

122122
} else {
123-
vscode.window.showErrorMessage(`Not connected to ${data.host}!`);
123+
vscode.window.showErrorMessage(`Not connected to ${data.host}${connected.error ? `: ${connected.error}` : '!'}`);
124124
}
125125
} catch (e) {
126126
vscode.window.showErrorMessage(`Error connecting to ${data.host}! ${e}`);
@@ -180,7 +180,7 @@ export class Login {
180180
if (connected.success) {
181181
vscode.window.showInformationMessage(`Connected to ${connectionConfig.host}!`);
182182
} else {
183-
vscode.window.showErrorMessage(`Not connected to ${connectionConfig.host}!`);
183+
vscode.window.showErrorMessage(`Not connected to ${connectionConfig.host}${connected.error ? `: ${connected.error}` : '!'}`);
184184
}
185185

186186
return true;

0 commit comments

Comments
 (0)