Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(cli): stop --format yaml from cutting off error messages (#1613)

i098168a0d481cca
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 68a0a89a4..40849565e 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -61,6 +61,7 @@ import {
} from "./artifact-export.js";
export { exportEnvironment } from "./artifact-export.js";
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
+import { parse as parseYaml } from "yaml";
import {
classifyConnectionFailure,
CodexSecurity,
@@ -8033,6 +8034,16 @@ export function skillCommandFailure(
}
function incurErrorMessage(output: string): string {
+ // YAML folds long strings across lines; JSON output keeps its serialized form.
+ if (!output.startsWith("{")) {
+ try {
+ const parsed: unknown = parseYaml(output);
+ if (isJsonObject(parsed) && typeof parsed["message"] === "string")
+ return parsed["message"];
+ } catch {
+ // Output that is not YAML (for example a Markdown table) uses the line scan.
+ }
+ }
const message = output
.split("\n")
.find((line) => line.startsWith("message: "))
diff --git a/sdk/typescript/tests-ts/cli-project-config.test.ts b/sdk/typescript/tests-ts/cli-project-config.test.ts
index 7b4f523c3..591a735e0 100644
--- a/sdk/typescript/tests-ts/cli-project-config.test.ts
+++ b/sdk/typescript/tests-ts/cli-project-config.test.ts
@@ -1252,3 +1252,23 @@ test.each([
);
},
);
+
+test.each(["yaml", "toon", "json"])(
+ "a long framework error keeps its whole message with --format %s",
+ async (format) => {
+ const root = await temporaryDirectory();
+ const missing = join(
+ root,
+ "a-directory-name-long-enough-to-make-yaml-fold-the-line",
+ "scan.yaml",
+ );
+ const { stderr, runCli } = createCliTest(main);
+ expect(
+ await runCli(
+ ["info", "-c", missing, "--format", format],
+ dependencies({ currentDirectory: root }),
+ ),
+ ).toBe(2);
+ expect(stderr.text()).toContain(missing);
+ },
+);