| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Use LanguagePrimitives.ConvertTo in GetSSHConnectionStringParameter and GetSSHConnectionIntParameter.
There was a problem hiding this comment.
Please add tests.
Sorry, something went wrong.
| private static string GetSSHConnectionStringParameter(object param) | ||
| { | ||
| if (param is string paramValue && !string.IsNullOrEmpty(paramValue)) | ||
| string paramValue = LanguagePrimitives.ConvertTo<string>(param); |
There was a problem hiding this comment.
ConvertTo() can throw PSInvalidCastException but we should keep PSArgumentException.
Sorry, something went wrong.
There was a problem hiding this comment.
Is there a circumstance where converting to string will throw?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, it is not common but possible (if someone creates ToString() method which throw).
Sorry, something went wrong.
| } | ||
|
|
||
| throw new PSArgumentException(RemotingErrorIdStrings.InvalidSSHConnectionParameter); | ||
| return LanguagePrimitives.ConvertTo<int>(param); |
There was a problem hiding this comment.
The same.
Sorry, something went wrong.
Any thoughts on that? If I try to test that the conversion works then we'll hit the interactive SSH prompt. I could give it a bad port and/or hostname, but that'll add ~5 seconds per test. If that's acceptable I'll add a few of those. |
Sorry, something went wrong.
|
I'd expect 2 tests for these two code paths modified. |
Sorry, something went wrong.
|
Ilya (@iSazonov) I've added tests and normalized the exception type. In the tests I used port 49151 since it's reserved and shouldn't be in use, but that was the result of a quick search so I'm open to suggestions. |
Sorry, something went wrong.
|
|
||
| It "<testName>" -TestCases $TestCasesSSHConnection { | ||
| param($scriptBlock) | ||
| { & $scriptBlock } | Should -Throw -ErrorId '2100,PSSessionOpenFailed' |
There was a problem hiding this comment.
It is out of the PR but I'd prefer to see more useful message.
Sorry, something went wrong.
|
Patrick Meinecke (@SeeminglyScience) Thanks for your contribution! |
Sorry, something went wrong.
|
🎉v7.0.0-preview.5 has been released which incorporates this pull request.:tada: Handy links: |
Sorry, something went wrong.
…match expected type (PowerShell#10720) Before the change if the hashtable value does not match the expected type exactly, an exception is thrown stating that the value was null.
| Back | FazBrowse Home | New Git URL |
PR Summary
Use LanguagePrimitives.ConvertTo when reading a hashtable provided to the SSHConnection parameter.
PR Context
Currently if the hashtable value does not match the expected type exactly, an exception is thrown stating that the value was null.
Fixes #10687
PR Checklist