Skip to content

zoo kcl lint --show-code panics on multi-line and non-ASCII findings; zoo kcl lint always exits 0 #1755

Description

@sneg55

zoo kcl lint --show-code panics on multi-line or non-ASCII findings, and zoo kcl lint always exits 0

Context: API Makeathon participant. Found while reviewing the lint command (which runs fully locally, no engine).

1. --show-code panics

src/cmd_kcl.rs:1739-1755:

if self.show_code {
    if start.line != end.line {
        unimplemented!()                          // raw panic, exit 101
    }
    let printable_line = code.lines().collect::<Vec<&str>>()[start.line as usize];
    println!("...", &printable_line[..(start.character as usize)], ...);  // byte-slice by char offset

Two problems:

  • Any finding whose span crosses a line boundary hits unimplemented!(), a raw Rust panic with a backtrace, instead of an error or a degraded rendering. The lint engine can produce multi-line spans and nothing upstream filters them.
  • start.character / end.character come from to_lsp_range (character offsets), but they are used to byte-slice printable_line. On a line with any multi-byte character before the finding (Ø, µ, a degree sign in a comment), the slice lands mid-codepoint and panics with "byte index is not a char boundary", or underlines the wrong columns.

2. lint always exits 0

CmdKclLint::run returns Ok(()) regardless of how many findings it printed (src/cmd_kcl.rs:1712-1759), so zoo kcl lint always exits 0 and cannot gate CI on lint findings.

Concrete failure

zoo kcl lint --show-code file.kcl on a file with a non-ASCII comment preceding a same-line finding aborts with a panic (exit 101, "please report this" backtrace), reading as a CLI crash rather than a lint result. And a CI job running zoo kcl lint passes even when findings exist.

Verify

Construct a KCL file where a lint finding sits after a // °C comment on the same line and run with --show-code, or code-review that unimplemented!() is reachable. Run zoo kcl lint on a file with findings and check $? (it is 0).

Suggested fix

Handle multi-line spans without panicking, slice by character (or convert LSP offsets to byte offsets) for the underline, and return a nonzero exit when findings are present (or behind a --deny flag).

Environment

Zoo CLI v0.2.184 (33534cd). Reviewed against the current main of KittyCAD/cli.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions