Skip to content

mdl: invalid units text makes a saved MDL file fail to open #862

Open

Description

@bpowers

A units string that is not a valid MDL unit expression is saved to MDL as-is, and the saved file then fails to open: the reader rejects the whole model with a units parse error such as expected unit name, found /.
The save should instead drop units it cannot write and warn, naming the variable.

Example

In the app, set a variable's units to 3.14 (or |, or text with a stray comma), save as MDL, and reopen the file.
The reader's units grammar accepts only unit names, 1, *, / and parentheses, so these fail.
A | fails because the writer replaces it with / (so it cannot end the field early), and a lone / is not a unit expression either.

Why it matters

Units are free text in the app, so a typo is enough to make a model's MDL export unopenable, with an error that does not say which variable is at fault.
Seen only in a property test, not a user report.

Fix

In the writer, check each units string with the MDL reader's own units parser; if it does not parse, write empty units and add an export warning naming the variable.
This keeps the change to the units field only: the | to / substitution is shared with comments, where it is wanted.

Alternative: make the reader keep or drop unparseable units with an import warning instead of failing the whole file.
That also helps hand-edited Vensim files, but changes the reader's error behavior for every import.

Pointers

  • src/simlin-engine/src/mdl/writer.rs: write_units_and_comment, sanitize_free_text
  • src/simlin-engine/src/mdl/parser.rs: parse_units_range, parse_unit_term
  • src/simlin-engine/src/mdl/writer_proptest.rs: units_free_text_is_structurally_safe

Activity

  1. added
    bug
    engine
    on Jul 7, 2026
  2. changed the title [-]engine: MDL writer units field re-import hard-fails on non-unit-expression text[/-] [+]mdl: invalid units text makes a saved MDL file fail to open[/+] on Oct 12, 2026
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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions