Skip to content

fix: map Mongo duplicate key error to DuplicatedJobError - #217

Merged
GiovaniGuizzo merged 2 commits into
sidequestjs:masterfrom
Tyagiquamar:fix/mongo-duplicated-job-error
Sep 22, 2026
Merged

GiovaniGuizzo merged 2 commits into
sidequestjs:masterfrom
Tyagiquamar:fix/mongo-duplicated-job-error

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Fixes #216 (follow-up to closed #85).

Was: MongoBackend.createNewJob did a bare insertOne, so a duplicate unique_digest surfaced as a raw MongoServerError E11000 while the SQL drivers throw DuplicatedJobError.

Now: duplicate-key failures (code 11000 / E11000 / unique_digest) throw DuplicatedJobError, and the conformance suite pins all drivers to that contract.

Where to look:

  • packages/backends/mongo/src/mongo-backend.ts (try/catch mapping)
  • packages/backends/backend-test/src/createNewJob.ts (expects DuplicatedJobError)

Tested: mongo conformance suite 85 passed against mongo:7 (MONGODB_URL 127.0.0.1:27777); eslint clean on both files. SQLite suite cannot run here (better-sqlite3 native bindings missing on Windows, fails at migration before any assertion).

GiovaniGuizzo
GiovaniGuizzo previously approved these changes Sep 21, 2026
@GiovaniGuizzo

Copy link
Copy Markdown
Contributor

Approved! Thanks for your contribution, @Tyagiquamar!

merencia
merencia previously approved these changes Sep 21, 2026
@GiovaniGuizzo

Copy link
Copy Markdown
Contributor

@Tyagiquamar there are failures now on MySQL. Can you please apply the same fix to that backend driver?

MySQL reports unique_digest collisions as ER_DUP_ENTRY (errno 1062)
with key sidequest_jobs.sidequest_jobs_unique_digest_unique, which
did not match the previous sidequest_jobs.unique_digest check.

createNewJob now maps those failures to DuplicatedJobError, matching
the Mongo backend contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Tyagiquamar
Tyagiquamar dismissed stale reviews from merencia and GiovaniGuizzo via c71b38d September 22, 2026 07:19
@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

@GiovaniGuizzo applied the same mapping on the MySQL driver. createNewJob now treats unique_digest duplicate-key failures (ER_DUP_ENTRY / errno 1062, key sidequest_jobs.sidequest_jobs_unique_digest_unique) as DuplicatedJobError, matching the Mongo contract.

The previously failing conformance cases (should not insert two jobs with the same unique digest) pass locally against mysql:8.

@GiovaniGuizzo
GiovaniGuizzo merged commit 9255b1a into sidequestjs:master Sep 22, 2026
6 checks passed
@GiovaniGuizzo

Copy link
Copy Markdown
Contributor

Merged! Thanks, @Tyagiquamar for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants