Skip to content

Commit 72df569

Browse files
committed
fix: address journey runner review comments
1 parent e294274 commit 72df569

3 files changed

Lines changed: 75 additions & 14 deletions

File tree

apps/cli-journey-e2e/scripts/prepare-next-app.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async function collectLocalRuntimeLogs(input) {
179179
} catch (error) {
180180
await input.writeFile(
181181
join(input.outputDir, "logs.stderr.log"),
182-
`failed to collect local runtime logs: ${error.message}\n`,
182+
`failed to collect local runtime logs: ${errorMessage(error)}\n`,
183183
);
184184
return;
185185
}
@@ -262,7 +262,11 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
262262
try {
263263
await prepareNextApp();
264264
} catch (error) {
265-
console.error(error instanceof Error ? error.message : String(error));
265+
console.error(errorMessage(error));
266266
process.exit(1);
267267
}
268268
}
269+
270+
function errorMessage(error) {
271+
return error instanceof Error ? error.message : String(error);
272+
}

apps/cli-journey-e2e/scripts/prepare-next-app.test.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,47 @@ test("collects local runtime logs when a CLI step fails", async () => {
138138
}
139139
});
140140

141+
test("records log collection failures thrown as non-Error values", async () => {
142+
const workDir = await mkdtemp(join(tmpdir(), "zitadel-journey-prepare-non-error-test-"));
143+
144+
try {
145+
await assert.rejects(
146+
prepareNextApp({
147+
env: {
148+
JOURNEY_CLI_PACKAGE: "@zitadel/cli",
149+
JOURNEY_SDK_NEXT_PACKAGE: "@zitadel/sdk-next",
150+
JOURNEY_WORK_DIR: workDir,
151+
},
152+
logMetadata: false,
153+
runCapture: async (command, args) => {
154+
if (args.includes("doctor")) {
155+
return { code: 0, stdout: `${JSON.stringify(okEnvelope(args))}\n`, stderr: "" };
156+
}
157+
if (args.includes("start")) {
158+
return {
159+
code: 1,
160+
stdout: `${JSON.stringify({ status: "error", message: "boom" })}\n`,
161+
stderr: "start failed",
162+
};
163+
}
164+
if (args.includes("logs")) {
165+
throw null;
166+
}
167+
throw new Error(`unexpected command: ${command} ${args.join(" ")}`);
168+
},
169+
}),
170+
/start exited 1/,
171+
);
172+
173+
assert.equal(
174+
await readFile(join(workDir, "logs.stderr.log"), "utf8"),
175+
"failed to collect local runtime logs: null\n",
176+
);
177+
} finally {
178+
await rm(workDir, { recursive: true, force: true });
179+
}
180+
});
181+
141182
async function writeGeneratedApp(appDir, registryUrl) {
142183
await writeFile(
143184
join(appDir, "package.json"),

apps/cli-journey-e2e/scripts/run-local.mjs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const packageDirs = [
2929
"packages/sdk-angular",
3030
];
3131

32-
const options = parseArgs(process.argv.slice(2));
32+
const options = parseArgsOrExit(process.argv.slice(2));
3333
const workDir = resolve(
3434
options.workDir || (await mkdtemp(join(tmpdir(), "zitadel-cli-journey-local-"))),
3535
);
@@ -150,7 +150,7 @@ try {
150150
} catch (error) {
151151
await collectDiagnostics();
152152
console.error("");
153-
console.error(`[journey-local] failed: ${error.message}`);
153+
console.error(`[journey-local] failed: ${errorMessage(error)}`);
154154
console.error(`[journey-local] diagnostics preserved in ${workDir}`);
155155
process.exitCode = 1;
156156
} finally {
@@ -164,6 +164,15 @@ try {
164164

165165
process.exit(process.exitCode ?? 0);
166166

167+
function parseArgsOrExit(args) {
168+
try {
169+
return parseArgs(args);
170+
} catch (error) {
171+
console.error(`[journey-local] ${errorMessage(error)}`);
172+
process.exit(1);
173+
}
174+
}
175+
167176
function parseArgs(args) {
168177
const parsed = {
169178
image: "",
@@ -175,11 +184,14 @@ function parseArgs(args) {
175184
const arg = args[index];
176185
switch (arg) {
177186
case "--backend": {
178-
const backend = readValue(args, ++index, arg);
179-
if (!["source", "image"].includes(backend)) {
180-
throw new Error(`--backend must be "source" or "image", got ${backend}`);
181-
}
182-
break;
187+
readValue(args, ++index, arg);
188+
throw new Error(
189+
[
190+
"--backend was removed from the journey runner.",
191+
"The journey now always exercises `npx @zitadel/cli@alpha start`.",
192+
"Remove `--backend`, or pass `--image <docker-tag>` / set ZITADEL_LOCAL_IMAGE to choose the local runtime image.",
193+
].join(" "),
194+
);
183195
}
184196
case "--image": {
185197
parsed.image = readValue(args, ++index, arg);
@@ -501,7 +513,7 @@ function runCapture(command, args, optionsForRun = {}) {
501513
}
502514

503515
function commandErrorDetail(error) {
504-
const message = error instanceof Error ? error.message : String(error);
516+
const message = errorMessage(error);
505517
const lines = message
506518
.split(/\r?\n/)
507519
.map((line) => line.trim())
@@ -541,7 +553,7 @@ async function collectDiagnostics() {
541553
);
542554
await writeFile(composeLogPath, `${result.stdout}${result.stderr}`);
543555
} catch (error) {
544-
await writeFile(composeLogPath, `failed to collect compose logs: ${error.message}\n`);
556+
await writeFile(composeLogPath, `failed to collect compose logs: ${errorMessage(error)}\n`);
545557
}
546558
}
547559

@@ -594,7 +606,7 @@ async function collectLocalRuntimeLogs() {
594606
} catch (error) {
595607
await writeFile(
596608
join(diagnosticsDir, "logs.stderr.log"),
597-
`failed to collect local runtime logs: ${error.message}\n`,
609+
`failed to collect local runtime logs: ${errorMessage(error)}\n`,
598610
);
599611
}
600612
}
@@ -623,7 +635,7 @@ async function cleanup() {
623635
try {
624636
await run("docker", composeArgs(["down", "-v", "--remove-orphans"]));
625637
} catch (error) {
626-
console.error(`[journey-local] docker compose cleanup failed: ${error.message}`);
638+
console.error(`[journey-local] docker compose cleanup failed: ${errorMessage(error)}`);
627639
}
628640
}
629641
}
@@ -636,7 +648,7 @@ async function resetLocalRuntime() {
636648
{ cwd: appDir, env: npxEnv() },
637649
);
638650
} catch (error) {
639-
console.error(`[journey-local] local runtime reset failed: ${error.message}`);
651+
console.error(`[journey-local] local runtime reset failed: ${errorMessage(error)}`);
640652
}
641653
}
642654

@@ -702,3 +714,7 @@ function npxEnv() {
702714
function log(message) {
703715
console.log(`[journey-local] ${message}`);
704716
}
717+
718+
function errorMessage(error) {
719+
return error instanceof Error ? error.message : String(error);
720+
}

0 commit comments

Comments
 (0)