Skip to content

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
}

Parameters

Exception

The error/exception object to format.

TypeRequiredPositionPipelineInput
[Object]true1true (ByValue)

ExceptionFormat

The format to use when rendering the exception. The default value is “Default”.

Valid Values:

  • Default
  • NoStackTrace
  • ShortenEverything
  • ShortenMethods
  • ShortenPaths
  • ShortenTypes
  • ShowLinks
TypeRequiredPositionPipelineInput
[String]false2false

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"
}
TypeRequiredPositionPipelineInput
[Hashtable]false3false

Syntax

Format-SpectreException [-Exception] <Object> [[-ExceptionFormat] <String>] [[-ExceptionStyle] <Hashtable>] [<CommonParameters>]