Repository navigation
fix: add code into errors - #1256
Conversation
Coverage Report for CI Build 30003303204Coverage increased (+0.09%) to 80.395%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
There was a problem hiding this comment.
LGTM. This is a well-tested, mechanical fix: it adds a required code field to the shared error response schema (previously silently stripped during serialization) and wires it through existing error paths (rate limiter, tenant-feature guard, renderer, 404s).
Extended reasoning...
Overview
The PR extends errorSchema (src/http/schemas/error.ts) to include a code field and adds a shared sharedErrorResponseSchemas object covering both 4xx and 5xx responses. It then threads code through the handful of places that construct error bodies by hand (tenant-feature plugin, render rate-limiter, image renderer's 404/abort responses) and swaps route-level response schemas from a bare 4xx ref to the shared 4xx/5xx schema across the object, vector, render, bucket, and cdn route groups. It also adds a new setRestNotFoundHandler that gives each top-level REST route group (bucket, object, render, cdn, vector) a schema-consistent 404 body instead of Fastify's default. The bulk of the diff (most of the line count) is test updates asserting the new code field and the new 404 behavior.
Security risks
None. This is response-shape/serialization only — no new auth, crypto, or data-exposure surface. The code values are drawn from the existing ErrorCode enum already used internally, so no new information is exposed that wasn't already computed server-side.
Level of scrutiny
Moderate scrutiny is warranted given the file count (44), but the actual behavioral change is narrow and mechanical: add a field to a schema, and consistently pass a code value everywhere an error object is already constructed. I traced the core error-handler (src/http/error-handler.ts, unchanged by this diff) and confirmed every code path there already emits code via ErrorCode/StorageError.render(), so extending the schema simply stops that field from being silently dropped by fastify's serializer rather than introducing new logic. The new not-found-handler.ts is also simple — it explicitly compiles and applies the errorSchema serializer for unmatched routes within each REST route group, verified against src/test/app.test.ts to confirm non-REST protocol handlers (S3, iceberg) are left untouched.
Other factors
Test coverage is extensive and directly targets the changed behavior — new tests assert code in bucket/object/vector/render error responses, new 404 tests per route group, and renderer abort/not-found tests. No CODEOWNER-restricted paths or auth/permission logic are touched. No bugs were reported by the bug-hunting pass, and my own read of the diff didn't surface any correctness concerns beyond what's already covered by tests.
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
d7b0a25 to
c3bab47
Compare
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Code is missing from shared error schema so it's removed in serialization.
What is the new behavior?
Extend error schema to include code, handling a few missing cases and cover with tests.
Additional context
Related to https://supabase.com/docs/guides/storage/debugging/error-codes
Related to supabase/supabase-js#2537