Skip to content

Commit

Permalink
Merge pull request Badgerati#831 from Badgerati/Issue-825
Browse files Browse the repository at this point in the history
Add new crash event hook
  • Loading branch information
Badgerati authored Sep 18, 2021
2 parents a27a80f + 0563aa2 commit 452867b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/Tutorials/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Pode lets you register scripts to be run when certain server events are triggere
* Terminate
* Restart
* Browser
* Crash

## Overview

Expand Down Expand Up @@ -48,3 +49,7 @@ Scripts registered to the `Restart` event will all be invoked whenever an intern
### Browser

Scripts registered to the `Browser` event will all be invoked whenever the server is told to open a browser, ie: when `Ctrl+B` is pressed.

### Crash

Scripts registered to the `Crash` event will all be invoked if the server ever terminates due to an exception being thrown.
1 change: 1 addition & 0 deletions src/Private/Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ function New-PodeContext
Terminate = [ordered]@{}
Restart = [ordered]@{}
Browser = [ordered]@{}
Crash = [ordered]@{}
}

# return the new context
Expand Down
2 changes: 1 addition & 1 deletion src/Private/Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function Invoke-PodeEvent
{
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type
)
Expand Down
1 change: 1 addition & 0 deletions src/Public/Core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function Start-PodeServer
$PodeContext.Tokens.Cancellation.Cancel()
}
catch {
Invoke-PodeEvent -Type Crash
$ShowDoneMessage = $false
throw
}
Expand Down
10 changes: 5 additions & 5 deletions src/Public/Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Register-PodeEvent
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type,

Expand Down Expand Up @@ -80,7 +80,7 @@ function Unregister-PodeEvent
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type,

Expand Down Expand Up @@ -119,7 +119,7 @@ function Test-PodeEvent
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type,

Expand Down Expand Up @@ -152,7 +152,7 @@ function Get-PodeEvent
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type,

Expand Down Expand Up @@ -182,7 +182,7 @@ function Clear-PodeEvent
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser')]
[ValidateSet('Start', 'Terminate', 'Restart', 'Browser', 'Crash')]
[string]
$Type
)
Expand Down

0 comments on commit 452867b

Please sign in to comment.