Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

A strict option that throws on a job file that fails to load #37

Open

Description

@thetutlage

Goal

Locator.registerFromGlob() imports each job file. When a file throws on import or has a syntax error, it logs the error at the error level, skips the file, and goes on (src/locator.ts). The caller cannot know that a file failed. queue:work of @adonisjs/queue must exit with code 1 when a job file fails to load (T-092). It needs an option that throws in place of the log.

  • Expected: with strict: true, registerFromGlob() and QueueManager.loadJobs() throw E_JOB_LOAD_FAILED for the first job file that fails to import.
  • Actual: they log the error and return the number of the other jobs.
  • Steps: a job file that contains throw new Error('boom'). Call Locator.registerFromGlob([file]).

Acceptance criteria

  • RegisterFromGlobOptions has strict?: boolean. With strict: true, a file that fails to import throws E_JOB_LOAD_FAILED at once, with the message Cannot load job from "<file>" and the import error in cause. Nothing is logged for that file.
  • QueueManager.loadJobs(locations?, options?) accepts { strict?: boolean } as its second argument and gives it to registerFromGlob(). locations stays optional, and undefined gives the configured locations.
  • With no strict option, or strict: false, the behaviour is the same as in 0.10.0: the error is logged at the error level, the file is skipped, and the other jobs are registered.
  • E_JOB_LOAD_FAILED is exported with the other errors of the package.
  • Tests prove strict: true for a file that throws on import and for a file with a syntax error, through registerFromGlob() and through loadJobs(). They also prove that a file with no default export does not throw with strict: true.
  • README.md documents the strict option.

Implementation decisions

  • src/exceptions.ts: E_JOB_LOAD_FAILED = createError<[file: string]>('Cannot load job from "%s"', 'E_JOB_LOAD_FAILED'), like the other errors of the file. Reason: the import error of a file that throws does not name the file, so the new error gives it, and cause keeps the original error.
  • src/locator.ts: in the catch of the import, when options.strict is true, throw new E_JOB_LOAD_FAILED([file], { cause: error }). Otherwise keep the log and the continue.
  • src/queue_manager.ts: loadJobs(locations = this.#locations, options: { strict?: boolean } = {}) passes strict with hotReload and logger.
  • strict applies only to a file that fails to import. A file with no default export, or a default export that is not a function, is still skipped with no error. Reason: the option is about a broken file, and the skip of other files is a separate behaviour.
  • Tests: tests/locator.spec.ts and tests/queue_manager.spec.ts, with the fs fixture that queue_manager.spec.ts already uses for broken_job.js.

Out of scope

  • A change to QueueManager.init() or its autoLoadJobs. init() keeps the log and the skip.
  • A change to the hot reload of a job before it runs.
  • The change of @adonisjs/queue that uses the option (T-092).

Hub task T-131. Edit the task in the hub, not this issue.

Activity

  1. added
    status: ready
    status: building
    status: review
    and removed
    status: ready
    status: building
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions