Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): Add top-level error handling to state machine #25995

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/gatsby/src/state-machines/develop/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ export const finishParentSpan = ({ parentSpan }: IBuildContext): void =>

export const saveDbState = (): Promise<void> => saveState()

export const logError: ActionFunction<IBuildContext, AnyEventObject> = (
_context,
event
) => {
reporter.error(event.data)
}

export const panic: ActionFunction<IBuildContext, AnyEventObject> = (
_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
Expand Down Expand Up @@ -158,4 +172,6 @@ export const buildActions: ActionFunctionMap<IBuildContext, AnyEventObject> = {
markSourceFilesClean,
saveDbState,
setQueryRunningFinished,
panic,
logError,
}
31 changes: 31 additions & 0 deletions packages/gatsby/src/state-machines/develop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
target: `initializingData`,
actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`],
},
onError: {
actions: `panic`,
},
},
},
// Sourcing nodes, customising and inferring schema, then running createPages
Expand Down Expand Up @@ -77,6 +80,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
],
target: `runningQueries`,
},
onError: {
actions: `logError`,
target: `waiting`,
},
},
},
// Running page and static queries and generating the SSRed HTML and page data
Expand Down Expand Up @@ -126,6 +133,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
target: `waiting`,
},
],
onError: {
actions: `logError`,
target: `waiting`,
},
},
},
// Recompile the JS bundle
Expand All @@ -136,6 +147,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
actions: `markSourceFilesClean`,
target: `waiting`,
},
onError: {
actions: `logError`,
target: `waiting`,
},
},
},
// Spin up webpack and socket.io
Expand All @@ -150,6 +165,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
`markSourceFilesClean`,
],
},
onError: {
actions: `panic`,
target: `waiting`,
},
},
},
// Idle, waiting for events that make us rebuild
Expand Down Expand Up @@ -183,6 +202,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
actions: `assignServiceResult`,
target: `recreatingPages`,
},
onError: {
actions: `panic`,
target: `waiting`,
},
},
},
// Almost the same as initializing data, but skips various first-run stuff
Expand Down Expand Up @@ -217,6 +240,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
],
target: `runningQueries`,
},
onError: {
actions: `logError`,
target: `waiting`,
},
},
},
// Rebuild pages if a node has been mutated outside of sourceNodes
Expand All @@ -230,6 +257,10 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
actions: `assignServiceResult`,
target: `runningQueries`,
},
onError: {
actions: `logError`,
target: `waiting`,
},
},
},
},
Expand Down