-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Brundage
committed
Jul 20, 2023
1 parent
f6071ac
commit a0d2bac
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
<# | ||
.SYNOPSIS | ||
Filters errors by line wildcard | ||
.DESCRIPTION | ||
Filters entries in $Error for items that a .Line like a wildcard. | ||
.EXAMPLE | ||
$error.LineLike("Get-*") | ||
#> | ||
param( | ||
# A wildcard pattern. | ||
[string] | ||
$Like | ||
) | ||
|
||
,@(foreach ($err in $this) { | ||
if ($err.InvocationInfo.Line -like $Like) { | ||
$err | ||
} | ||
}) |
This file contains 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,18 @@ | ||
<# | ||
.SYNOPSIS | ||
Filters errors by command pattern | ||
.DESCRIPTION | ||
Filters entries in $Error for items that have a .CommandLine matching the pattern. | ||
.EXAMPLE | ||
$error.LineMatc("^Get") | ||
#> | ||
param( | ||
# A regular expression. | ||
$Match | ||
) | ||
|
||
,@(foreach ($err in $this) { | ||
if ($err.InvocationInfo.Line -match $match) { | ||
$err | ||
} | ||
}) |
This file contains 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,25 @@ | ||
<# | ||
.SYNOPSIS | ||
Gets errors by line | ||
.DESCRIPTION | ||
Gets all lines that produced errors | ||
.EXAMPLE | ||
$error.ByLine | ||
#> | ||
$errorsByLine = | ||
[Collections.Generic.Dictionary[ | ||
string, | ||
[Collections.Generic.List[psobject]] | ||
]]::new([System.StringComparer]::OrdinalIgnoreCase) | ||
|
||
|
||
foreach ($err in $this) { | ||
|
||
$errLine = $err.InvocationInfo.Line | ||
if (-not $errLine) { continue } | ||
if (-not $errorsByLine[$errLine]) { | ||
$errorsByLine[$errLine] = [Collections.Generic.List[psobject]]::new() | ||
} | ||
$null = $errorsByLine[$errLine].Add($err) | ||
} | ||
$errorsByLine |
This file contains 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,23 @@ | ||
<# | ||
#> | ||
$errorsByType = | ||
[Collections.Generic.Dictionary[ | ||
type, | ||
[Collections.Generic.List[psobject]] | ||
]]::new() | ||
|
||
|
||
foreach ($err in $this) { | ||
|
||
$exceptionType = if ($err.Exception) { | ||
$err.Exception.GetType() | ||
} else { | ||
$err.GetType() | ||
} | ||
if (-not $errorsByType[$exceptionType]) { | ||
$errorsByType[$exceptionType] = [Collections.Generic.List[psobject]]::new() | ||
} | ||
$null = $errorsByType[$exceptionType].Add($err) | ||
} | ||
$errorsByType |
This file contains 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,15 @@ | ||
<# | ||
.SYNOPSIS | ||
Gets Error History | ||
.DESCRIPTION | ||
Gets the history items associated with PowerShell Errors | ||
.EXAMPLE | ||
$Error.History | ||
#> | ||
$historyIDS = @(foreach ($err in $this) { | ||
if ($err.InvocationInfo.HistoryId -gt 0) { | ||
$err.InvocationInfo.HistoryId | ||
} | ||
}) | ||
|
||
Get-History -Id $historyIDS |