Format-SpectreException
Description
Formats an error record/exception into a Spectre Console Exception which supports syntax highlighting.
See https://spectreconsole.net/exceptions for more information.
Examples
Example 1
This example demonstrates how to format an exception into a Spectre Console Exception with syntax highlighting.
try { Get-ChildItem -BadParam -ErrorAction Stop} catch { $_ | Format-SpectreException -ExceptionFormat ShortenEverything}
Example 2 This example uses custom formatting for the exception.
try { Get-ChildItem -BadParam -ErrorAction Stop} catch { $_ | Format-SpectreException -ExceptionStyle @{ Message = "#00ff00" Exception = "white" Method = "#ff0000 on orange1" ParameterType = "blue" ParameterName = "silver" Parenthesis = "silver" Path = "Yellow" LineNumber = "blue" Dimmed = "grey" NonEmphasized = "silver" }}
Parameters
Exception
The error/exception object to format.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Object] | true | 1 | true (ByValue) |
ExceptionFormat
The format to use when rendering the exception. The default value is “Default”.
Valid Values:
- Default
- NoStackTrace
- ShortenEverything
- ShortenMethods
- ShortenPaths
- ShortenTypes
- ShowLinks
Type | Required | Position | PipelineInput |
---|---|---|---|
[String] | false | 2 | false |
ExceptionStyle
The style to use when rendering the exception provided as a hashtable. e.g.
@{ Message = "red" Exception = "white" Method = "yellow" ParameterType = "blue" ParameterName = "silver" Parenthesis = "silver" Path = "Yellow" LineNumber = "blue" Dimmed = "grey" NonEmphasized = "silver"}
Type | Required | Position | PipelineInput |
---|---|---|---|
[Hashtable] | false | 3 | false |
Syntax
Format-SpectreException [-Exception] <Object> [[-ExceptionFormat] <String>] [[-ExceptionStyle] <Hashtable>] [<CommonParameters>]