Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvertFrom-StringData mistakenly emits a statement-terminating error when one of its input strings isn't well-formed #23793

Open
5 tasks done
mklement0 opened this issue May 13, 2024 · 2 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@mklement0
Copy link
Contributor

mklement0 commented May 13, 2024

Prerequisites

Steps to reproduce

With multiple, individual strings as input, ConvertFrom-StringData mistakenly aborts processing overall, via a statement-terminating error, once an incorrectly formatted string is encountered; the expected behavior would be to merely emit a non-terminating error in that event, and continue processing further inputs:

'foo=bar', 'broken', 'bar=baz' | ConvertFrom-StringData

As an aside:

Expected behavior

Name                           Value
----                           -----
foo                            bar
ConvertFrom-StringData: Data line 'broken' is not in 'name=value' format.
bar                            baz

That is, processing should have continued after the incorrectly formatted input string, and the output should be two hashtables, one for each valid input string.

Actual behavior

Name                           Value
----                           -----
foo                            bar
ConvertFrom-StringData: Data line 'broken' is not in 'name=value' format.

That is, overall processing was unexpectedly aborted when the broken input string was encountered.

Error details

No response

Environment data

PowerShell 7.5.0-preview.2

Visuals

No response

@mklement0 mklement0 added the Needs-Triage The issue is new and needs to be triaged by a work group. label May 13, 2024
@mklement0 mklement0 changed the title ConvertFrom-StringData mistakenly emits a statement-terminating error when one of its input strings isn't in the right format ConvertFrom-StringData mistakenly emits a statement-terminating error when one of its input strings isn't well-formed May 13, 2024
@237dmitry
Copy link

It ignors all of input strings, outputs them to host but you cannot set variable:

$res = 'a = 1', 'b = 2', 'c' | ConvertFrom-StringData     # $res is not defined
$res = 'Music', 'Fake', 'Pictures' | Get-item             # $res without "Fake"

@mklement0
Copy link
Contributor Author

Good point, @237dmitry: Because the error that is emitted is statement-terminating, you cannot even capture the hashtables that are created for the well-formed input strings, because this requires collecting the pipeline output, and since the error terminates the whole pipeline, no assignment is performed.
This problem too will go away once a non-terminating error is emitted instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

2 participants