Skip to content

fix(GG-3218): Add a strict mode to raise errors when params are missing - #4

Merged
cassandra-aq merged 1 commit into
mainfrom
feature/GG-3218
Nov 3, 2026
Merged

cassandra-aq merged 1 commit into
mainfrom
feature/GG-3218

Conversation

@cassandra-aq

@cassandra-aq cassandra-aq commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

When an expression uses a parameter that isn't defined, or whose value is None, the solver returns the parameter's name as a text string instead of failing. What happens next depends on the operator:

create_solver({})(["Greater", "a", 0.6])  # → False  (silent, looks like a real result)
create_solver({})(["Add", "a", 1])        # → 1      ("a" is silently skipped)
create_solver({})(["Multiply", "a", 2])   # → error

So a missing value can quietly produce a wrong result.

The change: an opt-in strict mode

solver = create_solver(params, strict=True)
  • If a parameter is missing or None, strict mode raises a MathJSONException. The message reads Parameter 'a' is not defined or Parameter 'a' is None.
  • The exception points at the smallest expression that uses the parameter (for example ["Greater", "a", 0.6], operator Greater), so callers can show which rule failed.
  • Without strict=True, nothing changes. Existing users of the library are not affected.

Points to check in review

  • Most of the work is in the name lookup at the end of f() in __main__.py. The return s at the very end is the line that turned unknown names into strings.
  • In strict mode, a plain string is treated as a parameter name. A literal text value must therefore be wrapped in Str: ["Str", "plasma"] returns "plasma". The README now says this.
  • A parameter whose value is a string is returned as-is; the solver doesn't look it up again as another parameter name.

Small related fixes

  • Str and Not now see values defined with Constants.
  • extract_variables used the wrong variable in its Constants branch. It also listed the text inside Str and Date as variables.
  • IsDefined was listed in the docs but never implemented. It now is.

@cassandra-aq
cassandra-aq merged commit 902151b into main Nov 3, 2026
2 checks passed
@cassandra-aq
cassandra-aq deleted the feature/GG-3218 branch November 3, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant