From 3550eacff3772fedc906865374e674f846d34d15 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Mon, 5 Oct 2026 19:02:35 +0800 Subject: [PATCH 1/2] feat: render comline-core's diagnostics properly in the CLI (Phase 3) Bumps the comline-core/comline-codegen pins to core#69 (Phase 1+2 of the error-reporting work: parse errors now render as real ariadne source snippets instead of Debug-dumped Vecs, routed through one shared Diagnostic type). core_err now branches on whether the wrapped error's detail is multi-line - a rendered snippet gets its own paragraph instead of being glued onto the ": " prefix on one line. The per-language-generator error bridge in generate.rs is left alone (documented why: those errors are about schema/package structure, not source text, so they carry no span to render a snippet against). New integration tests reproduce the exact reported bug end-to-end through the real CLI binary, for both a broken schema and a broken config.idp, asserting stderr never contains "ParseError {"/"FailedNode(" and does contain the filename plus a line:column-shaped location. --- Cargo.lock | 30 +++++------------------------- Cargo.toml | 21 +++++++++++---------- src/commands/generate.rs | 5 +++++ src/commands/mod.rs | 14 ++++++++++++-- tests/cli/check.rs | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15f9135..b8039c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,16 +343,6 @@ dependencies = [ "roff", ] -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width 0.1.14", -] - [[package]] name = "colorchoice" version = "1.0.4" @@ -389,7 +379,7 @@ dependencies = [ [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=a5b1b319e810fe5723ee94966ec174c6a1b2e7f1#a5b1b319e810fe5723ee94966ec174c6a1b2e7f1" +source = "git+https://github.com/ComlineProject/generation?rev=56826746326799e7cfbf988deb80156c3a4bcdfb#56826746326799e7cfbf988deb80156c3a4bcdfb" dependencies = [ "comline-core", "eyre", @@ -398,7 +388,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=6b3f4ffd027b37219efa36e167f769e7362821cc#6b3f4ffd027b37219efa36e167f769e7362821cc" +source = "git+https://github.com/ComlineProject/comline-rust?rev=9366ea18b706aed357c3c745f239c32797048780#9366ea18b706aed357c3c745f239c32797048780" dependencies = [ "comline-codegen", "comline-core", @@ -408,7 +398,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=56bea641f6d163120006e853bff4eec4d0a7c88e#56bea641f6d163120006e853bff4eec4d0a7c88e" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=132630a7d61ec7a2c6425b50bce716098befe617#132630a7d61ec7a2c6425b50bce716098befe617" dependencies = [ "comline-codegen", "comline-core", @@ -418,13 +408,12 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=5e6cc3af04964590b43c3c53f8924f474f00951e#5e6cc3af04964590b43c3c53f8924f474f00951e" +source = "git+https://github.com/ComlineProject/core?rev=f8861a8716ff597e8623ce0b3f067eda0ea1923b#f8861a8716ff597e8623ce0b3f067eda0ea1923b" dependencies = [ "ariadne", "bincode", "blake3", "chumsky", - "codespan-reporting", "comline-core-stdlib", "downcast-rs", "eyre", @@ -450,7 +439,7 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=5e6cc3af04964590b43c3c53f8924f474f00951e#5e6cc3af04964590b43c3c53f8924f474f00951e" +source = "git+https://github.com/ComlineProject/core?rev=f8861a8716ff597e8623ce0b3f067eda0ea1923b#f8861a8716ff597e8623ce0b3f067eda0ea1923b" [[package]] name = "concolor" @@ -1708,15 +1697,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "terminal_size" version = "0.4.3" diff --git a/Cargo.toml b/Cargo.toml index 66ecd14..61e996f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,17 +29,18 @@ toml = "0.8" # needs real I/O (git fetch, filesystem), so it's off by default for # `comline-core`'s wasm32 consumers (the playground editor, the language # server); the CLI is the one consumer that actually runs `comline build`. -comline-core = { git = "https://github.com/ComlineProject/core", rev = "5e6cc3af04964590b43c3c53f8924f474f00951e", features = ["deps"] } -# All three pinned to revs that already agree on comline-core@5e6cc3a -# (core#67's block-comment support) - bumped together: generation#34's -# branch-tip commit (comline-rust/comline-typescript's own codegen crates -# consume `comline-codegen`'s types, so this pins the exact same generation -# rev they do - a5b1b31, not generation's later merge commit, since Cargo +comline-core = { git = "https://github.com/ComlineProject/core", rev = "f8861a8716ff597e8623ce0b3f067eda0ea1923b", features = ["deps"] } +# All three pinned to revs that already agree on comline-core@f8861a8 +# (core#69 - the Diagnostic rename + dead-code cleanup half of the +# error-reporting work) - bumped together: generation#35's branch-tip +# commit (comline-rust/comline-typescript's own codegen crates consume +# `comline-codegen`'s types, so this pins the exact same generation rev +# they do - 5682674, not generation's later merge commit, since Cargo # only unifies a git dependency across byte-identical revs), then -# comline-rust#23 and comline-typescript#20. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "a5b1b319e810fe5723ee94966ec174c6a1b2e7f1" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "6b3f4ffd027b37219efa36e167f769e7362821cc", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "56bea641f6d163120006e853bff4eec4d0a7c88e", optional = true } +# comline-rust#24 and comline-typescript#21. +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "56826746326799e7cfbf988deb80156c3a4bcdfb" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "9366ea18b706aed357c3c745f239c32797048780", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "132630a7d61ec7a2c6425b50bce716098befe617", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole diff --git a/src/commands/generate.rs b/src/commands/generate.rs index a921604..e15a7d0 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -190,6 +190,11 @@ fn generate_once(work_dir: &Path, overrides: &Overrides) -> Result<()> { }, default_framing: t.default_framing.clone(), }; + // Deliberately not `core_err`: a generator's errors are about + // schema/package *structure* (e.g. a namespace that's both a + // schema and a parent of deeper schemas), not source *text* - + // they carry no span to render a snippet against, so there's + // nothing for the multi-line branch there to do. let files = generator(&request).map_err(|e| miette!("`{}` generator: {e}", t.language))?; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 18825ad..9a96463 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -28,7 +28,17 @@ pub fn ensure_project(dir: &Path) -> Result<()> { } /// Wrap a `comline-core` (`eyre`) error as a `miette` one for the reporting -/// path. `{:#}` renders the message plus its cause chain, without a backtrace. +/// path. `{:#}` renders the message plus its cause chain, without a +/// backtrace. `comline-core`'s own diagnostics (parse/validation errors) +/// now arrive as a multi-line, already-rendered `ariadne` source snippet +/// (`comline_core::diagnostics::render`) - gluing `"{context}: "` onto the +/// front of that would run the prefix into the snippet's own box-drawing on +/// one line, so a multi-line detail gets its own paragraph instead. pub fn core_err(context: &str, e: impl std::fmt::Display) -> miette::Report { - miette::miette!("{context}: {e:#}") + let detail = format!("{e:#}"); + if detail.contains('\n') { + miette::miette!("{context}:\n\n{detail}") + } else { + miette::miette!("{context}: {detail}") + } } diff --git a/tests/cli/check.rs b/tests/cli/check.rs index 03e145a..d559fb7 100644 --- a/tests/cli/check.rs +++ b/tests/cli/check.rs @@ -52,6 +52,42 @@ fn reports_a_broken_schema() { .stderr(predicate::str::contains("validation failed")); } +#[test] +fn a_broken_schema_reports_a_source_snippet_not_a_debug_dump() { + let temp = tempfile::tempdir().unwrap(); + let project = fixture_project(temp.path()); + fs::write(project.join("src/main.ids"), "struct Greeting {\n / name: string\n}\n").unwrap(); + + comline_cmd() + .current_dir(&project) + .arg("check") + .assert() + .failure() + .code(1) + .stderr(predicate::str::contains("ParseError {").not()) + .stderr(predicate::str::contains("FailedNode(").not()) + .stderr(predicate::str::contains("main.ids")) + .stderr(predicate::str::contains("unexpected token")) + .stderr(predicate::str::is_match(r"\d+:\d+").unwrap()); +} + +#[test] +fn a_broken_config_idp_reports_a_source_snippet_not_a_debug_dump() { + let temp = tempfile::tempdir().unwrap(); + let project = fixture_project(temp.path()); + fs::write(project.join("config.idp"), "congregation test\nspecification_version =\n").unwrap(); + + comline_cmd() + .current_dir(&project) + .arg("check") + .assert() + .failure() + .code(1) + .stderr(predicate::str::contains("ParseError {").not()) + .stderr(predicate::str::contains("FailedNode(").not()) + .stderr(predicate::str::contains("config.idp")); +} + #[test] fn std_is_usable_and_checked() { let temp = tempfile::tempdir().unwrap(); From ba6449af81679cd3a473fdc1d6b7eedc28495c2c Mon Sep 17 00:00:00 2001 From: Kinflou Date: Mon, 5 Oct 2026 19:05:28 +0800 Subject: [PATCH 2/2] style: cargo fmt --- tests/cli/check.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/cli/check.rs b/tests/cli/check.rs index d559fb7..a9fea70 100644 --- a/tests/cli/check.rs +++ b/tests/cli/check.rs @@ -56,7 +56,11 @@ fn reports_a_broken_schema() { fn a_broken_schema_reports_a_source_snippet_not_a_debug_dump() { let temp = tempfile::tempdir().unwrap(); let project = fixture_project(temp.path()); - fs::write(project.join("src/main.ids"), "struct Greeting {\n / name: string\n}\n").unwrap(); + fs::write( + project.join("src/main.ids"), + "struct Greeting {\n / name: string\n}\n", + ) + .unwrap(); comline_cmd() .current_dir(&project) @@ -75,7 +79,11 @@ fn a_broken_schema_reports_a_source_snippet_not_a_debug_dump() { fn a_broken_config_idp_reports_a_source_snippet_not_a_debug_dump() { let temp = tempfile::tempdir().unwrap(); let project = fixture_project(temp.path()); - fs::write(project.join("config.idp"), "congregation test\nspecification_version =\n").unwrap(); + fs::write( + project.join("config.idp"), + "congregation test\nspecification_version =\n", + ) + .unwrap(); comline_cmd() .current_dir(&project)