Skip to content

[ts-command-line] Fix env var name shown in EnvironmentVariableParser error messages#5831

Open
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix/ts-command-line-env-var-name-in-error-message
Open

[ts-command-line] Fix env var name shown in EnvironmentVariableParser error messages#5831
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix/ts-command-line-env-var-name-in-error-message

Conversation

@LeSingh1

Copy link
Copy Markdown
Contributor

When parseAsList encounters a malformed JSON array in an environment variable, it throws
two possible error messages. Both messages were accidentally interpolating the variable's
value (environmentValue) instead of the variable's name (envVarName). This means a user
who set MY_VAR='[u' would see:

The [u environment variable value looks like a JSON array but failed to parse: ...

instead of the expected:

The MY_VAR environment variable value looks like a JSON array but failed to parse: ...

The fix is a two-character change in each template string, swapping environmentValue for
envVarName. The existing test assertion and snapshot were written against the wrong output,
so those are corrected to match the intended behavior.

I noticed this while reading EnvironmentVariableParser.ts. No open issue existed for it
so I'm filing the fix directly. Happy to open a tracking issue first if that's preferred.

…e in error messages

When a list parameter's environment variable contained an invalid JSON
array, the two error messages in EnvironmentVariableParser.parseAsList
accidentally interpolated the variable's value (environmentValue) where
the variable's name (envVarName) was intended.  The result was confusing
messages like "The [u environment variable value looks like a JSON array
but failed to parse" instead of "The MY_VAR environment variable value
looks like a JSON array but failed to parse".

Update the two affected template strings to use envVarName, and correct
the corresponding test assertion and snapshot that were written to match
the old (wrong) output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

1 participant