MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / writeInternalError

Function writeInternalError

internal/server/server.go:3142–3208  ·  view source on GitHub ↗

writeInternalError logs the real error server-side and sends a generic message to the client. This prevents leaking SQL errors, file paths, and other internal details.

(w http.ResponseWriter, err error)

Source from the content-addressed store, hash-verified

3140// message to the client. This prevents leaking SQL errors, file paths,
3141// and other internal details.
3142func writeInternalError(w http.ResponseWriter, err error) {
3143 // A database that was too busy (statement, lock or idle timeout, deadlock,
3144 // context deadline) is retryable and rolled back: answer it as such, never
3145 // as a 500 (TASK-4278). First, so no later arm can claim it. This funnel
3146 // has no request, so it cannot tell a write from a read and uses the
3147 // neutral wording.
3148 if store.IsDBRetryable(err) {
3149 slog.Warn("database busy", "error", err)
3150 writeBusy(w, err, false)
3151 return
3152 }
3153 // The store's NUL refusal is a DECISION, not a fault, and it is mapped
3154 // here rather than at each handler for the same reason Layer A lives at
3155 // the driver: this is the one funnel every 500 already passes through, so
3156 // mapping it once covers every handler that exists and every one that will
3157 // (DOC-2823 S1). Enumerating error blocks is what the item-title unit had
3158 // to do three times in one function before a structural test caught the
3159 // third.
3160 //
3161 // 400, matching what the HTTP gate answers for the SAME value refused at
3162 // the door. Two statuses for one rule would be the layers disagreeing
3163 // again, in the response this time instead of in the predicate.
3164 //
3165 // The honest residual: a value can reach the store from something the
3166 // SERVER composed rather than the caller supplied — that is BUG-2814's
3167 // re-emit population — and for those a 400 tells the caller their request
3168 // was bad when it was our stored data. It is still the better answer than
3169 // 500, because the request is understood and will be refused identically
3170 // on retry, and the log line below keeps the detail. If the re-emit case
3171 // ever needs its own status, it needs its own error type first.
3172 if reason, ok := nulRefusalReason(err); ok {
3173 slog.Warn("write refused: invalid text parameter", "error", err)
3174 writeError(w, http.StatusBadRequest, "bad_request", reason)
3175 return
3176 }
3177 // The outbox row cap is likewise a decision, not a fault, and is mapped in
3178 // the same funnel for the same reason (BUG-2827). 413 with a *_too_large
3179 // code follows the house precedent set by rename_cascade_too_large rather
3180 // than inventing a second spelling for "this operation produces more than
3181 // the server will process in one go".
3182 //
3183 // The literal reading of 413 is that the REQUEST entity is too large, and
3184 // here the request is small while the event it derives is not. Taken
3185 // alone that argues for 422. It loses to consistency: an operator watching
3186 // for cascade refusals should not have to know which of two size bounds
3187 // fired to know which status to grep for, and the message says plainly
3188 // what was actually too big.
3189 //
3190 // Composed from the TYPED fields, never by splicing err.Error(), so no
3191 // wrapper the call path added is published to the caller.
3192 var oversized *store.OversizedOutboxPayloadError
3193 if errors.As(err, &oversized) {
3194 slog.Warn("write refused: outbox payload over the size limit",
3195 "event_type", oversized.EventType, "bytes", oversized.Bytes, "limit", oversized.Limit)
3196 // The message names WHAT was measured, because the store refuses on two
3197 // different measurements — the member content before marshalling, and
3198 // the row as stored — and a caller told only "%d bytes" for both
3199 // cannot reconcile two different numbers for one mutation.

Callers 15

handleSetRoleParkMethod · 0.85
handleClearRoleParkMethod · 0.85
resolveBuiltinItemMethod · 0.85
handleGetItemBuiltinMethod · 0.85
handleBuiltinUpdateMethod · 0.85
handleCollabMethod · 0.85
writeCollabAccessErrorFunction · 0.85
handleItemsSortOrderMethod · 0.85
canReorderItemMethod · 0.85
handleListMembersMethod · 0.85

Calls 5

IsDBRetryableFunction · 0.92
writeBusyFunction · 0.85
nulRefusalReasonFunction · 0.85
writeErrorFunction · 0.85
ErrorMethod · 0.45