Repository navigation
fix(module): run under strict mode and fail the import on a load error #84
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
Merged
+851
−261
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| function Get-IslPropertyValue { | ||
| <# | ||
| .SYNOPSIS | ||
| Gets a named value from a dictionary or an object, or nothing when it has none. | ||
|
|
||
| .DESCRIPTION | ||
| Data that reaches the module from outside has optional members and comes in two shapes: a | ||
| Graph reply is a dictionary or an object depending on how it was read, a rule or a settings | ||
| table is a hashtable the caller wrote, and a CIM call that fails returns nothing at all. | ||
| Under strict mode a read of a member that is not there is an error, so every such read goes | ||
| through this function, which returns nothing for a missing input, a missing key and a | ||
| missing property alike. | ||
|
|
||
| A collection is unrolled on the way out, like the output of any function. Wrap the call in | ||
| @() where the value is a list. | ||
|
|
||
| .PARAMETER InputObject | ||
| The dictionary or object to read from. Nothing is returned when it is $null. | ||
|
|
||
| .PARAMETER Name | ||
| The key or property name. | ||
|
|
||
| .EXAMPLE | ||
| Get-IslPropertyValue -InputObject $page -Name '@odata.nextLink' | ||
|
|
||
| The address of the next page of a Graph reply, or nothing on the last page. | ||
|
|
||
| .EXAMPLE | ||
| @(Get-IslPropertyValue -InputObject $policy -Name 'assignments') | ||
|
|
||
| The assignments of a policy as an array, empty when the reply has none. | ||
|
|
||
| .INPUTS | ||
| None. | ||
|
|
||
| .OUTPUTS | ||
| System.Object. The value, or nothing when the input has no such member. | ||
| #> | ||
| [CmdletBinding()] | ||
| [OutputType([object])] | ||
| param( | ||
| [Parameter()] | ||
| [AllowNull()] | ||
| [object]$InputObject, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$Name | ||
| ) | ||
|
|
||
| if ($null -eq $InputObject) { | ||
| return | ||
| } | ||
|
|
||
| if ($InputObject -is [System.Collections.IDictionary]) { | ||
| # Called through the interface: a generic dictionary implements this method explicitly, | ||
| # and PowerShell does not find it on the object itself | ||
| if (([System.Collections.IDictionary]$InputObject).Contains($Name)) { | ||
| return $InputObject[$Name] | ||
| } | ||
| return | ||
| } | ||
|
|
||
| $property = $InputObject.PSObject.Properties[$Name] | ||
| if ($null -ne $property) { | ||
| return $property.Value | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
catchthat only rethrows is what makes a file that does not parse fail the import. Dot-sourcing such a file raises an error that ends only that statement, so without thetrythe loop went on and the module imported without the commands of the file. Rethrown fromcatch, the error ends the root module.Module.Contract.Tests.ps1imports a copy with such a file in a new process and checks that the module is not loaded afterwards.