Skip to content

Commit

Permalink
🩹 fix(patch): bud.after sync callback error
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymears committed Jun 17, 2024
1 parent 29afac7 commit 6a0a421
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 0 additions & 5 deletions examples/node-api/node-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const bud = await factory()
*/
bud.setPath(`@dist`, `dist/build-a`)

/**
* Add extensions
*/
await bud.extensions.add([`@roots/bud-swc`])

/**
* Run build
*/
Expand Down
9 changes: 8 additions & 1 deletion sources/@roots/bud-framework/src/methods/after/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ export const after: after = function (
fn: ((app: Bud) => any) | ((app: Bud) => Promise<any>),
onError?: (error: Error) => unknown,
): Bud {
const handleError = onError ?? this.catch

this.hooks.action(`compiler.done`, async bud => {
await fn(bud).catch(onError ?? bud.catch)
try {
await bud.resolvePromises()
await fn(bud)
} catch (error) {
handleError(error)
}
})

return this
Expand Down
10 changes: 4 additions & 6 deletions sources/@roots/bud-hooks/src/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {BudError} from '@roots/bud-support/errors'
import {Hooks} from '../base/base.js'

/**
* Synchronous hooks registry
*
* @remarks
* Supports sync values
* Event hooks
*/
export class EventHooks extends Hooks<EventsStore> {
@bind
Expand All @@ -22,12 +19,13 @@ export class EventHooks extends Hooks<EventsStore> {

for await (const action of this.store[id] as any) {
this.logger.info(`running ${id}`)

try {
await action(...value)
await this.app.resolvePromises()
} catch (error) {
this.logger.error(`problem running ${id} callback`)
throw BudError.normalize(error)
this.logger.error(`problem running ${id} callback`, error)
this.app.catch(error)
}
}

Expand Down

0 comments on commit 6a0a421

Please sign in to comment.