Repository navigation
fix: never let a failed rollback skip the write callbacks' error handling - #57
Merged
Merged
Conversation
Registering a recording with "Add surgery & insertion device if missing" crashed in registerSurgery and createRecording with 'Output argument "connObj" ... not assigned' from dj.conn. connect_tech hands its credentials straight to dj.conn and never stores them in dj.config, so dj.conn() only works while the +dj/conn.m MATLAB resolves still holds its saved connection. On the rig it held none (its persistent cleared, or a second DataJoint copy on the path, such as the Add-On the ViRMEn startup loads), and the vendored copy returns without an output. The tables kept working because each schema keeps its own connection. createRecording had already moved the files to cup when it crashed outside any try, so the recording was never registered. The new tableConn(<table>) returns the connection of the table's schema. Every callback that ran a transaction or raw query through dj.conn now uses it, so the transaction is also on the connection the inserts use. createRecording takes it before moving any files, and every write callback gets the connection and starts the transaction inside its try and cancels only an open one, so a failure is reported instead of escaping. Fixes #50 Assisted-by: ClaudeCode:claude-opus-5-5
…ling The five DB write callbacks (registerSurgery, createRecording, CreateNewJob, RerunJob, RegisterPreParamList) called conn.cancelTransaction first thing in their catch block. That runs a ROLLBACK query, which throws when the connection dropped and cannot reconnect, and then the rest of the catch never ran: no error dialog, no Slack report, the button stayed disabled and the GUI "Busy". In registerSurgery the surgery dialog stayed open, so createRecording stayed blocked in addSurgeryData's uiwait. The new cancelOpenTransaction(conn, err) rolls back an open transaction inside its own try/catch. It returns the caught error unchanged, or, if the rollback failed too, an error with the same identifier whose message appends "(rollback also failed: ...)" and keeps both errors as causes. Each callback now calls it in place of the inline cancel; the rest of each catch block is unchanged. Fixes #55 Assisted-by: ClaudeCode:claude-opus-5-5
It grepped the five write callbacks for cancelTransaction, so it broke on harmless rewording. The remaining tests cover cancelOpenTransaction itself. Assisted-by: ClaudeCode:claude-opus-5-5
This was referenced Dec 1, 2026
createRecording showed 'Recording was not createdLost connection ...', and RegisterPreParamList and registerSurgery ran their message into the error the same way. The others used a bare space. Every error dialog that appends err.message now uses ': '. Assisted-by: ClaudeCode:claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Fixes #55
Follows #51 (merged).
Problem
After #51, each of the five DB write callbacks (
registerSurgery,createRecording,CreateNewJob,RerunJob,RegisterPreParamList) starts itscatchblock withconn.cancelTransaction. That runs aROLLBACKquery, which throws when the connection dropped and cannot reconnect. Then the rest of thecatchnever runs:registerSurgery, the surgery dialog is never closed, socreateRecordingstays blocked inaddSurgeryData'suiwaitIn
createRecordingthis happens after the files were already moved to cup, so a failed registration would go unreported.Fix
cancelOpenTransaction(conn, err). It cancels an open transaction inside its owntry/catchand never throws.MExceptionwith the same identifier, the message<original message> (rollback also failed: <rollback message>), and both errors as causes, so the original stack is kept. The dialog and the Slack report therefore still show the original error first and mention the rollback failure.err = cancelOpenTransaction(conn, err);in place of the inline cancel. Four keep theirexist('conn', 'var')guard;createRecordingalways hasconnby then. The rest of eachcatchblock is unchanged. (A failed or skipped surgery registration still moves and registers the recording #56 also edits thecreateRecordingandregisterSurgerycatch blocks; this PR only touches the rollback lines there.):before it.createRecordingused to show "Recording was not createdLost connection ...", andRegisterPreParamListandregisterSurgeryran their text into the error the same way; the others used a bare space.Screenshots
The error dialog of
createRecordingwhen the insert fails and the rollback fails too. Before, the failing rollback skipped this dialog entirely.Rendered in MATLAB R2023b by calling the PR's code with a stand-in figure, not on a rig.
cancelOpenTransactionwas given a stand-in connection whose rollback fails.Tests
tests/TestCancelOpenTransaction.m, added to CI, README and AGENTS.md. It needs no DB: the new fixturedjconnfixture.FakeConnectionhas acancelTransactionthat throws, the waydj.Connection/cancelTransactiondoes on a dropped connection.%in the message.dj.Connectionwith no transaction sends no query.8bd2fb5c(Undefined function 'cancelOpenTransaction').uvx prek run --all-filespasses.Not tested: a dropped connection during a real registration through the GUI on a rig.
Assisted-by: ClaudeCode:claude-opus-5-5