Skip to content

Conversation

@jackdcasey
Copy link
Contributor

@jackdcasey jackdcasey commented Apr 20, 2020

PR Summary

Fix inconsistent exception message in -replace operator

PR Context

The exception message returned when passing three or more values to -replace, -ireplace or -creplace is not consistent with the actual operator used:

PS> "foo" -replace "f", "j", "h"
InvalidOperation: The -ireplace operator allows only two elements to follow it, not 3.
PS> "foo" -ireplace "f", "j", "h"
InvalidOperation: The -ireplace operator allows only two elements to follow it, not 3.
PS> "foo" -creplace "f", "j", "h"
InvalidOperation: The -replace operator allows only two elements to follow it, not 3.

My proposed changes would change the exception messages to:

PS> "foo" -replace "f", "j", "h"
InvalidOperation: The -ireplace/-replace operator allows only two elements to follow it, not 3.
PS> "foo" -ireplace "f", "j", "h"
InvalidOperation: The -ireplace/-replace operator allows only two elements to follow it, not 3.
PS> "foo" -creplace "f", "j", "h"
InvalidOperation: The -creplace operator allows only two elements to follow it, not 3.

Due to the way these parameters are passed as a boolean, we don't have visibility into exactly what parameter was used. For this reason -ireplace and -replace "share" the same error message.

Closes #12333

PR Checklist

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 21, 2020
@iSazonov iSazonov added this to the 7.0.x-Servicing-Consider milestone Apr 21, 2020
@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Apr 26, 2020
@jackdcasey jackdcasey requested a review from iSazonov April 26, 2020 22:01
@adityapatwardhan adityapatwardhan merged commit 767899d into PowerShell:master Apr 28, 2020
@iSazonov
Copy link
Collaborator

@jackdcasey Thanks for your contribution!

@jackdcasey jackdcasey deleted the ReplaceOperator_VerboseExceptionMessage branch April 28, 2020 17:58
@ghost
Copy link

ghost commented May 19, 2020

🎉v7.1.0-preview.3 has been released which incorporates this pull request.:tada:

Handy links:

@TravisEz13
Copy link
Member

I don't think this meets the bar to backport

@TravisEz13 TravisEz13 removed this from the 7.0.x-Servicing-Consider milestone Jun 8, 2020
@TravisEz13
Copy link
Member

Triage determined this does not meet the bar for backport

@iSazonov
Copy link
Collaborator

iSazonov commented Jun 9, 2020

Should we set 7.1.0-preview.3 for history?

@TravisEz13 TravisEz13 added this to the 7.1.0-preview.3 milestone Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Operator InvalidOperation Exception Message

5 participants