From 40e8dbc6fb358a12cdd5099acef10d8552107d87 Mon Sep 17 00:00:00 2001 From: noah1400 <48360809+noah1400@users.noreply.github.com> Date: Sun, 11 Oct 2026 11:55:20 +0200 Subject: [PATCH] CLI: --pdf-options that is no JSON object is an error `run --pdf-options '[1]' --export a.pdf` panicked when the PDF's path was added to the options (exit status 101). The value is now checked where it is read. Co-Authored-By: Claude Opus 5.5 --- apps/designcraft-cli/src/main.rs | 4 ++++ apps/designcraft-cli/tests/cli.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/designcraft-cli/src/main.rs b/apps/designcraft-cli/src/main.rs index 54f57b77a..94a1a11ef 100644 --- a/apps/designcraft-cli/src/main.rs +++ b/apps/designcraft-cli/src/main.rs @@ -268,6 +268,10 @@ fn run(args: &[String]) -> Result<(), String> { "--scale" => scale = val()?.parse().map_err(|_| "bad --scale")?, "--pdf-options" => { pdf_opts = serde_json::from_str(&val()?).map_err(|e| format!("--pdf-options: {e}"))?; + // The export adds its path to them. + if !pdf_opts.is_object() { + return Err("--pdf-options: expected a JSON object".into()); + } } "--export" => { let out = val()?; diff --git a/apps/designcraft-cli/tests/cli.rs b/apps/designcraft-cli/tests/cli.rs index 4e749a0cd..90fa062cc 100644 --- a/apps/designcraft-cli/tests/cli.rs +++ b/apps/designcraft-cli/tests/cli.rs @@ -185,6 +185,19 @@ fn closed_stdout_ends_quietly() { assert!(out.status.success() && !err.contains("panicked"), "{:?}: {err}", out.status); } +/// `--pdf-options` that was JSON but no object (`[1]`) panicked when the PDF's path was added to it. +#[test] +fn run_pdf_options_that_are_no_object_are_an_error() { + let pdf = std::env::temp_dir().join(format!("dc-cli-options-{}.pdf", std::process::id())); + for options in ["[1]", "\"all\"", "1", "null"] { + let out = cli().args(["run", "--sample", "--pdf-options", options, "--export", pdf.to_str().unwrap()]).output().unwrap(); + let err = String::from_utf8_lossy(&out.stderr); + assert!(!out.status.success(), "{options}: {err}"); + assert!(err.contains("--pdf-options") && !err.contains("panicked"), "{options}: {err}"); + } + assert!(!pdf.exists()); +} + /// `--scale`, `--page` and `--pdf-options` apply to the exports after them; one with no export /// after it was silently ignored. #[test]