fix: make --ext-str-file lazy via importstr#1035
Open
He-Pin wants to merge 3 commits into
Open
Conversation
Motivation: --ext-str-file should behave like Jsonnet importstr: missing files should only fail when the bound variable is evaluated. sjsonnet read the file eagerly during CLI binding parsing, so even unused bindings failed. Modification: Generate an importstr expression for file-backed string bindings, matching go-jsonnet's verbatim-string escaping. Keep stdin bindings eager as string literals because stdin cannot be lazily reopened. Add CLI golden tests for used missing files, unused missing files, and relative-path reads. Result: Used missing --ext-str-file bindings now fail through the normal import error path, while unused missing bindings are lazy and evaluation succeeds.
874ab83 to
4c353e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
--ext-str-fileeagerly read the file during CLI argument parsing, causing a crash when the file was missing — even if the external variable was never used by the Jsonnet program. Reference implementations (C++ jsonnet, go-jsonnet, jrsonnet) defer the file read untilstd.extVaris evaluated.--ext-str-file missing.json(unused)NoSuchFileExceptionModification
importstr @'path'code instead of eagerly reading viaos.read.std.extVaris evaluated, using the normal Jsonnet import mechanism.v.replace("'", "''")matches go-jsonnet's verbatim string literal convention.-or/dev/stdin) remains eager since stdin cannot be lazily reopened.@unusedannotation to thewdparameter inparseBindingssince it's no longer used after making file reads lazy.Result
Couldn't import fileerror and proper stack trace.