Skip to content

Record which controller action or job an error came from - #115

Merged
fractaledmind merged 1 commit into
mainfrom
feature/readable-error-context
Oct 16, 2026
Merged

fractaledmind merged 1 commit into
mainfrom
feature/readable-error-context

Conversation

@fractaledmind

Copy link
Copy Markdown
Owner

Fixes #37.

Since Rails 7.1, Rails puts the current controller or job into every error's context. The sanitizer stored any object as just its class, so occurrences showed "controller" => "#<UsersController>", and a record passed in context became "#<User>".

Now:

  • Requests record controller: "UsersController#show" and params, taken from request.filtered_parameters, so the app's filter_parameters apply.
  • Jobs record job (the class), job_id, queue and arguments. Arguments go through filter_parameters too.
  • Records anywhere in the context are stored as their GlobalID (gid://app/User/1). Unsaved records keep the class-name form.

Context the app sets itself wins: params: or arguments: passed to Rails.error.set_context aren't overwritten. Job arguments are sanitized before filtering, so a proc in filter_parameters can't copy a record into an unsaved one and lose its GlobalID.

This needs no new settings and no patching of controllers or jobs, because Rails already supplies the objects. The README gains a short section on what an occurrence records. It also answers #44: job errors already reach Solid Errors through the Rails executor with Solid Queue, Sidekiq and GoodJob.

The tests use a real request and a real job in the dummy app, and check that params and arguments are filtered. Mutants that skip the filtering or the GlobalID conversion each fail a test.

🤖 Generated with Claude Code

Rails puts the current controller or job in the error context, but it was
stored as "#<UsersController>". It's now the action and its filtered params,
or the job's class, id, queue and filtered arguments, and records anywhere in
the context are stored as GlobalIDs. Fixes #37.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@fractaledmind
fractaledmind merged commit 9365c8e into main Oct 16, 2026
17 checks passed
@fractaledmind
fractaledmind deleted the feature/readable-error-context branch October 16, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More information in the context of each exception

1 participant