Mongo createNewJob leaks raw E11000 instead of DuplicatedJobError (follow-up to #85)
Follow-up to closed #85 (MongoServerError: E11000 duplicate key error on unique_digest with the Mongo backend). That report was closed, but the underlying defect is still present on master.
Problem
MongoBackend.createNewJob (packages/backends/mongo/src/mongo-backend.ts) does a bare insertOne. migrate() creates a unique partial index on unique_digest, so enqueueing two jobs with the same digest fails with a raw driver error:
MongoServerError: E11000 duplicate key error collection: ....sidequest_jobs index: unique_digest_1 ...
Cross-driver contract break
The SQL drivers map this exact situation to DuplicatedJobError (packages/core/src/backends/duplicated-job-error.ts):
packages/backends/backend/src/sql-backend.ts(createNewJob, try/catch checkingsidequest_jobs.unique_digest/sidequest_jobs_unique_digest_active_idx)packages/backends/mysql/src/mysql-backend.ts(same mapping)
So unique(...).enqueue(...) twice (via JobBuilder.enqueue, packages/engine/src/job/job-builder.ts) throws DuplicatedJobError on Postgres/MySQL/SQLite but a raw MongoServerError on Mongo. Any caller catching DuplicatedJobError (docs advertise graceful duplicate handling) breaks only on Mongo.
Expected
Mongo maps duplicate-key failures on unique_digest (code 11000 / E11000 / unique_digest message) to DuplicatedJobError, and the conformance suite (packages/backends/backend-test/src/createNewJob.ts, currently only rejects.toThrow()) asserts DuplicatedJobError so all four drivers are pinned to the same contract.
Repro
- Configure the Mongo backend and run migrations.
Sidequest.build(Job).unique(true).enqueue(...)twice with identical digests.- Second call throws
MongoServerErrorE11000 instead ofDuplicatedJobError.