Skip to content

Validate CLI numeric limits#1083

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/cli-numeric-option-validation
Open

Validate CLI numeric limits#1083
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/cli-numeric-option-validation

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Motivation:
sjsonnet accepted invalid numeric CLI limits. --max-stack 0 and --max-stack -1 could still evaluate constant expressions, but the same settings make function-stack checks fail immediately once evaluation needs a stack frame. --max-trace -1 entered evaluation and behaved as an undocumented full-trace setting. --max-parser-recursion-depth -1 reached the parser and reported Parsing exceeded maximum recursion depth of -1 instead of being rejected as an invalid CLI value.

This is a CLI compatibility and input-validation issue rather than a Jsonnet language or stdlib semantics issue. C++ jsonnet and go-jsonnet both reject invalid values for the shared stack/trace flags during CLI parsing; --max-parser-recursion-depth is sjsonnet-specific, so the other implementations have no comparable CLI flag. jrsonnet differs for --max-stack 0 but rejects negative numeric values at its CLI parser.

Case C++ jsonnet observed go-jsonnet observed jrsonnet observed sjsonnet before this PR sjsonnet after this PR
--exec 1 --max-stack 0 Rejects ERROR: invalid --max-stack value: 0 Rejects ERROR: invalid --max-stack value: 0 Prints 1 Prints 1 Rejects ERROR: invalid --max-stack value: 0
--exec 1 --max-stack -1 Rejects ERROR: invalid --max-stack value: -1 Rejects ERROR: invalid --max-stack value: -1 Rejects invalid CLI value Prints 1 Rejects ERROR: invalid --max-stack value: -1
--exec "error \"x\"" --max-trace -1 Rejects ERROR: invalid --max-trace value: -1 Rejects ERROR: invalid --max-trace value: -1 Rejects invalid CLI value Enters evaluation and reports sjsonnet.Error: x Rejects ERROR: invalid --max-trace value: -1
--exec 1 --max-trace 0 Prints 1 Prints 1 Prints 1 Prints 1 Prints 1
--exec 1 --max-parser-recursion-depth -1 No comparable CLI flag No comparable CLI flag No comparable CLI flag Parser error Parsing exceeded maximum recursion depth of -1 Rejects ERROR: invalid --max-parser-recursion-depth value: -1
--exec 1 --max-parser-recursion-depth 0 No comparable CLI flag No comparable CLI flag No comparable CLI flag Prints 1 Prints 1
--exec "[1]" --max-parser-recursion-depth 0 No comparable CLI flag No comparable CLI flag No comparable CLI flag Parser error Parsing exceeded maximum recursion depth of 0 Parser error Parsing exceeded maximum recursion depth of 0

Modification:
Validate --max-stack >= 1, --max-trace >= 0, and --max-parser-recursion-depth >= 0 after CLI argument normalization and before constructing Settings. Add JVM CLI regression tests for --max-stack 0, --max-stack -1, --max-trace -1, --max-parser-recursion-depth -1, and the --max-parser-recursion-depth 0 boundary.

Result:
Invalid numeric CLI limits now fail before evaluation or parsing with user-facing CLI errors. The change matches C++ jsonnet and go-jsonnet for shared invalid stack/trace values, preserves documented --max-trace 0 full-trace behavior, and keeps the existing sjsonnet-specific --max-parser-recursion-depth 0 boundary semantics.

References:

  • C++ jsonnet cmd/jsonnet.cpp rejects --max-stack < 1 and --max-trace < 0.
  • go-jsonnet cmd/jsonnet/cmd.go rejects --max-stack < 1 and --max-trace < 0.
  • sjsonnet readme.md documents --max-parser-recursion-depth but gives no negative-value semantics.

Motivation:

sjsonnet accepted invalid numeric CLI limits for stack frames, trace cropping, and parser recursion depth. Non-positive stack limits created a broken runtime setting, negative trace limits behaved like an undocumented full-trace setting, and negative parser recursion depth reached the parser as Parsing exceeded maximum recursion depth of -1.

Modification:

Validate --max-stack >= 1, --max-trace >= 0, and --max-parser-recursion-depth >= 0 after CLI parsing and before constructing Settings. Add JVM CLI regression tests for invalid stack, trace, and parser-depth values, and preserve the boundary behavior that --max-trace 0 keeps a full trace and --max-parser-recursion-depth 0 still allows non-recursive expressions.

Result:

Invalid numeric CLI limits now fail before evaluation or parsing with user-facing CLI errors. Stack and trace behavior matches C++ jsonnet and go-jsonnet for shared flags, while the sjsonnet-specific parser-depth flag now rejects only the invalid negative range.

References:

C++ jsonnet cmd/jsonnet.cpp rejects --max-stack < 1 and --max-trace < 0.

go-jsonnet cmd/jsonnet/cmd.go rejects --max-stack < 1 and --max-trace < 0.

sjsonnet readme.md documents --max-parser-recursion-depth without a negative-value meaning.
@He-Pin He-Pin force-pushed the fix/cli-numeric-option-validation branch from 8e83f97 to fb74077 Compare July 4, 2026 09:39
@He-Pin He-Pin changed the title Validate CLI stack and trace limits Validate CLI numeric limits Jul 4, 2026
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