diff --git a/packages/gatsby/src/state-machines/develop/actions.ts b/packages/gatsby/src/state-machines/develop/actions.ts index 56fc89edb4ae3..fd278117881e5 100644 --- a/packages/gatsby/src/state-machines/develop/actions.ts +++ b/packages/gatsby/src/state-machines/develop/actions.ts @@ -129,6 +129,20 @@ export const finishParentSpan = ({ parentSpan }: IBuildContext): void => export const saveDbState = (): Promise => saveState() +export const logError: ActionFunction = ( + _context, + event +) => { + reporter.error(event.data) +} + +export const panic: ActionFunction = ( + _context, + event +) => { + reporter.panic(event.data) +} + /** * Event handler used in all states where we're not ready to process a file change * Instead we add it to a batch to process when we're next idle @@ -158,4 +172,6 @@ export const buildActions: ActionFunctionMap = { markSourceFilesClean, saveDbState, setQueryRunningFinished, + panic, + logError, } diff --git a/packages/gatsby/src/state-machines/develop/index.ts b/packages/gatsby/src/state-machines/develop/index.ts index 780451562e3f5..62e690ac2f496 100644 --- a/packages/gatsby/src/state-machines/develop/index.ts +++ b/packages/gatsby/src/state-machines/develop/index.ts @@ -45,6 +45,9 @@ const developConfig: MachineConfig = { target: `initializingData`, actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`], }, + onError: { + actions: `panic`, + }, }, }, // Sourcing nodes, customising and inferring schema, then running createPages @@ -77,6 +80,10 @@ const developConfig: MachineConfig = { ], target: `runningQueries`, }, + onError: { + actions: `logError`, + target: `waiting`, + }, }, }, // Running page and static queries and generating the SSRed HTML and page data @@ -126,6 +133,10 @@ const developConfig: MachineConfig = { target: `waiting`, }, ], + onError: { + actions: `logError`, + target: `waiting`, + }, }, }, // Recompile the JS bundle @@ -136,6 +147,10 @@ const developConfig: MachineConfig = { actions: `markSourceFilesClean`, target: `waiting`, }, + onError: { + actions: `logError`, + target: `waiting`, + }, }, }, // Spin up webpack and socket.io @@ -150,6 +165,10 @@ const developConfig: MachineConfig = { `markSourceFilesClean`, ], }, + onError: { + actions: `panic`, + target: `waiting`, + }, }, }, // Idle, waiting for events that make us rebuild @@ -183,6 +202,10 @@ const developConfig: MachineConfig = { actions: `assignServiceResult`, target: `recreatingPages`, }, + onError: { + actions: `panic`, + target: `waiting`, + }, }, }, // Almost the same as initializing data, but skips various first-run stuff @@ -217,6 +240,10 @@ const developConfig: MachineConfig = { ], target: `runningQueries`, }, + onError: { + actions: `logError`, + target: `waiting`, + }, }, }, // Rebuild pages if a node has been mutated outside of sourceNodes @@ -230,6 +257,10 @@ const developConfig: MachineConfig = { actions: `assignServiceResult`, target: `runningQueries`, }, + onError: { + actions: `logError`, + target: `waiting`, + }, }, }, },