Skip to content

Commit 7070fd3

Browse files
authored
Fix CLI output parsing (#1270)
Main change: `bundle summary` and `bundle validate` were failing for dabs project with many resources. CLI process outputs json in multiple chunks if it's too big, and we were joining them with `\n` control char, breaking json parsing. Confirmed that the output is still properly separated into new lines for non json output (since new lines are embedded in the process output in that case). Second fix is porting this PR to the bundle-integ branch: #1266
1 parent 91eb344 commit 7070fd3

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

packages/databricks-vscode/resources/python/00-databricks-init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def wrapper(*args, **kwargs):
5252
def load_env_from_leaf(path: str) -> bool:
5353
curdir = path if os.path.isdir(path) else os.path.dirname(path)
5454
env_file_path = os.path.join(curdir, ".databricks", ".databricks.env")
55-
if os.path.exists(os.path.dirname(env_file_path)):
55+
if os.path.exists(env_file_path):
5656
with open(env_file_path, "r") as f:
5757
for line in f.readlines():
5858
key, value = line.strip().split("=", 1)

packages/databricks-vscode/src/cli/CliWrapper.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {execFile as execFileCb} from "node:child_process";
1111
import {withFile} from "tmp-promise";
1212
import {writeFile, readFile} from "node:fs/promises";
1313
import {when, spy, reset, instance, mock} from "ts-mockito";
14-
import {CliWrapper} from "./CliWrapper";
14+
import {CliWrapper, waitForProcess} from "./CliWrapper";
1515
import path from "node:path";
1616
import os from "node:os";
1717
import crypto from "node:crypto";
@@ -22,6 +22,8 @@ import {ProfileAuthProvider} from "../configuration/auth/AuthProvider";
2222
import {isMatch} from "lodash";
2323
import {removeUndefinedKeys} from "../utils/envVarGenerators";
2424
import {writeFileSync} from "fs";
25+
import {ChildProcess, ChildProcessWithoutNullStreams} from "child_process";
26+
import {Readable} from "stream";
2527

2628
const execFile = promisify(execFileCb);
2729
const cliPath = path.join(__dirname, "../../bin/databricks");
@@ -260,3 +262,28 @@ nothing = true
260262
}
261263
});
262264
});
265+
266+
describe("waitForProcess", () => {
267+
it("should return correctly formatted stdout and stderr", async () => {
268+
const process = new ChildProcess();
269+
const stdoutChunks = [`{"hello": "wor`, `ld"}`];
270+
const stderrChunks = [`{"error": "no`, `oo"}`];
271+
process.stdout = new Readable({
272+
read() {
273+
this.push(stdoutChunks.shift());
274+
},
275+
});
276+
process.stderr = new Readable({
277+
read() {
278+
this.push(stderrChunks.shift());
279+
},
280+
});
281+
const waitPromise = waitForProcess(
282+
process as ChildProcessWithoutNullStreams
283+
);
284+
process.emit("close", 0);
285+
const {stdout, stderr} = await waitPromise;
286+
assert.equal(stdout, `{"hello": "world"}`);
287+
assert.equal(stderr, `{"error": "nooo"}`);
288+
});
289+
});

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ProcessError extends Error {
6161
}
6262
}
6363

64-
async function waitForProcess(
64+
export async function waitForProcess(
6565
p: ChildProcessWithoutNullStreams,
6666
onStdOut?: (data: string) => void,
6767
onStdError?: (data: string) => void
@@ -87,13 +87,13 @@ async function waitForProcess(
8787
if (code === 0) {
8888
resolve();
8989
} else {
90-
reject(new ProcessError(stderr.join("\n"), code));
90+
reject(new ProcessError(stderr.join(""), code));
9191
}
9292
});
9393
p.on("error", (e) => new ProcessError(e.message, null));
9494
});
9595

96-
return {stdout: stdout.join("\n"), stderr: stderr.join("\n")};
96+
return {stdout: stdout.join(""), stderr: stderr.join("")};
9797
}
9898

9999
async function runBundleCommand(

0 commit comments

Comments
 (0)