Skip to content

Commit 7f0a86a

Browse files
committed
Additional logging
1 parent c5ef32b commit 7f0a86a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/connection/sqlJob.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ export class SQLJob {
5757
const connection = instance.getConnection();
5858
return new Promise((resolve, reject) => {
5959
// Setting QIBM_JAVA_STDIO_CONVERT and QIBM_PASE_DESCRIPTOR_STDIO to make sure all PASE and Java converters are off
60-
const startingCommand = `QIBM_JAVA_STDIO_CONVERT=N QIBM_PASE_DESCRIPTOR_STDIO=B exec ` + ServerComponent.getInitCommand();
60+
const startingCommand = `QIBM_JAVA_STDIO_CONVERT=N QIBM_PASE_DESCRIPTOR_STDIO=B execggg ` + ServerComponent.getInitCommand();
6161

6262
ServerComponent.writeOutput(startingCommand);
6363

64-
const a = connection.client.connection.exec(startingCommand, {}, (err: any, stream: any, options: {encoding: `binary`}) => {
64+
const a = connection.client.connection.exec(startingCommand, (err: any, stream: any, options: {encoding: `binary`}) => {
6565
if (err) {
6666
reject(err);
6767
ServerComponent.writeOutput(err);
6868
}
69+
6970
let outString = ``;
7071

71-
stream.on(`data`, (data: Buffer) => {
72+
stream.stderr.on(`data`, (data: Buffer) => {
73+
ServerComponent.writeOutput(data.toString());
74+
})
75+
76+
stream.stdout.on(`data`, (data: Buffer) => {
7277
outString += String(data);
7378
if (outString.endsWith(`\n`)) {
7479
let thisMsg = outString;
@@ -111,20 +116,16 @@ export class SQLJob {
111116
async connect(): Promise<ConnectionResult> {
112117
this.channel = await this.getChannel();
113118

114-
this.channel.on(`error`, () => {
119+
this.channel.on(`error`, (err) => {
120+
ServerComponent.writeOutput(err);
115121
this.dispose();
116122
})
117123

118124
this.channel.on(`close`, (code: number) => {
125+
ServerComponent.writeOutput(`Exited with code ${code}.`)
119126
this.dispose();
120-
121-
if (code !== 0) {
122-
throw new Error(`Ended with ${code}`);
123-
}
124127
})
125128

126-
this.status = JobStatus.Ready;
127-
128129
const props = Object
129130
.keys(this.options)
130131
.map(prop => {
@@ -154,6 +155,10 @@ export class SQLJob {
154155
throw new Error(connectResult.error || `Failed to connect to server.`);
155156
}
156157

158+
if (this.status === JobStatus.Ended) {
159+
throw new Error(`Failed to connect properly.`);
160+
}
161+
157162
this.id = connectResult.job;
158163
this.status = JobStatus.Ready;
159164

0 commit comments

Comments
 (0)