mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-17 15:46:58 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8547a9fca4
commit
40e8dbc6fb
2 files changed
+17
No files matched your search
@@ -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()?;
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user