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

Fix NRE when assigning null to arrayoption in hashtable #2219

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

fflaten
Copy link
Collaborator

@fflaten fflaten commented Jul 16, 2022

PR Summary

GetArrayOrNull() throws a NRE when value is null, ex. when Run.Path was set to $null in a hashtable. Added null-check to return before any use of .GetType() etc.

Fixing this hashtable-scenario because Pester ignores null-values while casting from hashtable and the error didn't make it clear which option had the problem:

InvalidArgument: Cannot convert value "System.Collections.Hashtable" to type "PesterConfiguration". Error: "Object reference not set to an instance of an object."

Fix #2026

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@fflaten
Copy link
Collaborator Author

fflaten commented Jul 16, 2022

There's a difference between assigning null in a hashtable and directly to the options in a PesterConfiguration-object. During casting from hashtable, null-values are ignored in general. Assigning to options in a configuration-object allows null in most cases, except for booloptions which throws an NRE.

Should we check for null in direct assignments in advanced config in general so both hashtables and direct assignment behave equally? Ex. null-valued paths, scriptblocks etc. are only going to cause issues later on.

@fflaten fflaten changed the title Fix NRE when assigning null array-option from hashtable Fix NRE when assigning null to arrayoption in hashtable Jul 18, 2022
@nohwnd nohwnd merged commit ca86dcd into pester:main Oct 3, 2022
@fflaten fflaten deleted the fix-nullarraymerge branch October 3, 2022 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants