Skip to content

Hook execution: double callback on throw + swallowed hook-load errors #5

@dalberola

Description

@dalberola

Two issues in the hooks pipeline (agent-reported; [needs repro] but grounded in the code).

1. try/catch can invoke the callback twice

packages/dredd/lib/TransactionRunner.js:361-405 (runHookWithData). The try/catch wraps the entire callback chain, so an error thrown after this.runHook(...) (e.g. inside runHookCallback()) is caught and runHookCallback() is called again. The code itself comments that this is "very problematic."

Fix: wrap only the this.runHook() call, or guard with a once-flag so the callback fires exactly once.

2. Hook-load errors swallowed

packages/dredd/lib/addHooks.js:23-34 (loadHookFile). An invalid hook file only emits logger.warn and execution continues without the hooks the user expected — unlike the fail-fast hookHandlerError pattern used elsewhere.

Decision needed: propagate the error (fail fast) vs. keep warn-and-continue. If kept, document it as intentional.

Tasks

  • Narrow the try/catch in runHookWithData and/or add a once-guard on the callback.
  • Decide and implement fail-fast vs. documented warn-and-continue for hook-load errors.
  • Tests covering a throwing hook and an unloadable hook file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions