Skip to content

Commit 5dd2d20

Browse files
committed
feat: Implement smart default onCrash
1 parent a3c8857 commit 5dd2d20

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/interfaces/ServiceConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface ServiceConfig {
6969

7070
/**
7171
* A function to be executed each time the service crashes.
72-
* Defaults to `() => {}`.
72+
* Defaults to `ctx => { if (!ctx.isServiceReady) throw new Error('Crashed before becoming ready') }`.
7373
*
7474
* This function is called with an {@link OnCrashContext} object as its only argument.
7575
*

src/validateAndNormalizeConfig.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ function processServiceConfig(
8080
const merged = {
8181
dependencies: [],
8282
cwd: '.',
83-
// no default command
83+
command: undefined, // no default command
8484
env: process.env,
8585
ready: () => Promise.resolve(),
8686
forceKillTimeout: 5000,
87-
onCrash: () => {},
87+
onCrash: (ctx: OnCrashContext) => {
88+
if (!ctx.isServiceReady) throw new Error('Crashed before becoming ready')
89+
},
8890
logTailLength: 0,
8991
minimumRestartDelay: 1000,
9092
...removeUndefinedProperties(defaults),

0 commit comments

Comments
 (0)