Skip to content

cli: Warning-severity diagnostics are printed with an "error" prefix #919

Closed

Description

@bpowers

Problem

simlin-cli prints Warning-severity diagnostics with an "error" prefix, so advisory warnings read as hard failures.

Reproduce:

cargo run -p simlin-cli -- simulate --ltm test/conveyors/covid19_severity.stmx

Output includes lines like:

error in model 'main': ModelError{conveyor_ltm_degraded: ...}

conveyor_ltm_degraded is a DiagnosticSeverity::Warning. It tells the user that LTM link/loop scores through the conveyor are approximate. Printed with an error in model ... prefix, it reads as a compilation failure -- but the simulation ran and produced results.

This surfaced after commit 2d574720 ("cli: enable ltm before harvesting diagnostics"), which made the CLI actually harvest the diagnostics it had previously been dropping. The formatting bug is older; that commit just made it reachable.

Mechanism

Two places drop the severity:

  1. simlin_engine::errors::format_diagnostic (src/simlin-engine/src/errors.rs:275) hardcodes the word "error" into the rendered message:

    message: Some(format!("error in model '{}': {}", diag.model, err)),

    and again for the Equation arm (error in model '{}' variable '{}': {}). The resulting FormattedError struct (errors.rs:35) has no severity field at all, so the severity present on db::Diagnostic is discarded at the format boundary.

  2. report_formatted_errors / print_formatted_error in src/simlin-cli/src/main.rs:413-429 just eprintln! the pre-rendered message. They have no severity to switch on even if they wanted to.

Why it matters

  • User-facing and actively misleading. A user running --ltm on a conveyor model is told "error" for something that is advisory. The natural reaction is to assume the run is invalid and stop trusting the output, or to go hunting for a model bug that does not exist.
  • It also hides real errors. With warnings and errors rendered identically, there is nothing to grep or scan for. simlin-cli's exit code and has_model_errors / has_variable_errors flags are severity-blind too, so a "warning" contributes to has_model_errors.
  • The information is already there: db::Diagnostic carries DiagnosticSeverity. Only the printer ignores it.

Components affected

  • src/simlin-cli/src/main.rs (report_formatted_errors, print_formatted_error, and the has_model_errors / has_variable_errors gating)
  • src/simlin-engine/src/errors.rs (FormattedError, format_diagnostic, format_diagnostic_with_datamodel, collect_formatted_errors)

Note the second is a shared type consumed by libsimlin / the GUI, so a fix should consider whether those consumers want the severity too (they almost certainly do -- the same advisory-rendered-as-error problem exists wherever FormattedError.message is displayed verbatim).

Possible approaches

  1. Add a severity: DiagnosticSeverity field to FormattedError and populate it in format_diagnostic / format_unit_error / format_equation_error. Stop baking the literal word "error" into message; either render the severity word from the field at print time, or have the formatter emit warning in model '...' when appropriate.
  2. Have print_formatted_error route warnings and errors distinctly (prefix, and possibly stream), and make has_model_errors / has_variable_errors count only Error-severity diagnostics so warnings do not affect exit status or the handle_simulation_error path.
  3. Audit the other FormattedError.message consumers for the same conflation before changing the string, since the "error in model" prefix is likely load-bearing in test assertions.

Discovery

Found while fixing the conveyor-engine branch: --ltm on a conveyor model prints its conveyor_ltm_degraded advisory as an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions