Stop putting raw errors on screen (audit L-4) #146
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
qwc-open/asiakirjat!146
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/user-facing-errors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Audit item L-4. Independent of #144 and #145.
What was showing
Handlers passed
err.Error()straight intohttp.Error. Creating a user with a taken username answered the browser with:Driver text, table and column name, SQLite error code. Robot creation and the built-in docs deploy did the same, and the archive/PDF upload paths did it with filesystem errors — which carry absolute storage paths.
None of it helps the person reading it, and it describes the schema and the layout on disk to anyone who can reach an admin form.
What replaces it
Two helpers in
internal/handler/errors.gosplit the audiences:userErrorfor HTML endpoints,jsonUserErrorfor the API. Both log the real error with context (project slug, username, version tag) and send the user a message saying what failed and what they can do — "the username or email may already be taken", "check that it is a supported format, within the size limits, and contains no absolute or parent paths".The browser upload path renders a page rather than calling
http.Error, so it gained an explicit log line instead.One message stays verbatim, with a comment explaining why: an invalid version keep pattern reports the regular expression the admin just typed (
missing closing )). That error describes their input, not our internals, and showing it is the point.Tests
internal/handler/user_errors_test.goposts a duplicate username to the real admin endpoint and asserts the response says what failed while containing none ofUNIQUE,constraint,sqlite,users.username,SQL. It fails onmainwith the string quoted above — I checked by stashing the fix rather than assuming.Full suite green.
Assisted by Claude Opus 5.