fix: use throw instead of return for simpleError() calls#1416
Conversation
simpleError() returns never type since it throws HTTPException internally, so all callers should use throw instead of return for consistency and correct error handling semantics. Updated 39 files across _backend to use throw simpleError() instead of return simpleError(). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
Warning Rate limit exceeded@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 11 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR systematically converts error handling patterns across backend functions from returning simpleError responses to throwing them, shifting approximately 40 files from value-based error returns to exception-based control flow. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
simpleError() returns never type since it throws HTTPException internally, so all callers should use throw instead of return for consistency and correct error handling semantics. Updated 39 files across _backend to use throw simpleError() instead of return simpleError(). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…-go/capgo into riderx/fix-simpleError-throw
7fbefb4 to
b729662
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
supabase/functions/_backend/triggers/cron_email.ts (1)
78-90: Bug:getFunComparison()uses??where||(and dynamic last-index) is intended.
As written, stats above the max threshold will likely produceindex === -1and throw at Line 88.Proposed fix
function getFunComparison(comparison: keyof typeof funComparisons, stat: number): string { const thresholdsForComparisons = thresholds[comparison] + const lastIndex = thresholdsForComparisons.length - 1 const index = thresholdsForComparisons.findIndex((threshold, index) => { const thresholdGreaterThenStat = threshold >= stat - const lastIndexAndStatGreaterOrEqualThreshold = index === 2 && stat >= threshold + const lastIndexAndStatGreaterOrEqualThreshold = index === lastIndex && stat >= threshold - return thresholdGreaterThenStat ?? lastIndexAndStatGreaterOrEqualThreshold + return thresholdGreaterThenStat || lastIndexAndStatGreaterOrEqualThreshold }) if (index === -1 || index >= 3) throw new Error(`Cannot find index for fun comparison, ${index}`) return funComparisons[comparison][index] }supabase/functions/_backend/utils/plugin_parser.ts (1)
57-59: Redundant condition in version_name normalization.The check
!body.version_nameon line 58 is always false because it's inside theif (body.version_name)block. Onlybody.version_name === 'builtin'can ever be true here.Proposed fix
if (body.version_name) { - body.version_name = (body.version_name === 'builtin' || !body.version_name) ? body.version_build : body.version_name + body.version_name = body.version_name === 'builtin' ? body.version_build : body.version_name }
🤖 Fix all issues with AI agents
In @supabase/functions/_backend/private/download_link.ts:
- Around line 32-33: The thrown error uses the wrong error code string; update
the simpleError call so the error code is "not_authorized" instead of
"not_authorize" in the conditional that checks (error || !auth?.user?.id) —
locate the throw simpleError('not_authorize', 'Not authorize') and change the
first argument to 'not_authorized' while leaving the message intact.
🧹 Nitpick comments (11)
supabase/functions/_backend/utils/hono_middleware_stripe.ts (1)
24-42: Middleware now correctly short-circuits on validation errors and continues the chain viaawait next().
Good alignment with the “exception-based” error flow, and addingawait next()prevents silently stopping the pipeline on success. As per coding guidelines/learnings, the structured logging withrequestId: c.get('requestId')is consistent.Minor: the second env check at Line 27 duplicates the first one; consider dropping the repeated
getEnv(...)conditions to reduce noise.supabase/functions/_backend/private/store_top.ts (1)
19-21:throw simpleError(...)on missingdatais consistent with the new flow.
Optional: include{ mode }(and/or upstream errors if available) inmoreInfoto make this actionable when it fires.supabase/functions/_backend/private/latency.ts (1)
9-17: Good: switch tothrow simpleError(...)for correct control flow.This matches
simpleError(...): neversemantics and avoids “error-as-return-value” ambiguity.Suggested resilience tweak (ensure pg client always closes)
app.get('/', async (c) => { cloudlog({ requestId: c.get('requestId'), message: 'Latency check' }) const pgClient = getPgClient(c, true) - const res = await selectOne(pgClient) - - await closeClient(c, pgClient) - if (!res) - throw simpleError('cannot_get_apps', 'Cannot get apps') + try { + const res = await selectOne(pgClient) + if (!res) + throw simpleError('cannot_get_apps', 'Cannot get apps') + } + finally { + await closeClient(c, pgClient) + } return c.json(BRES) })supabase/functions/_backend/private/set_org_email.ts (1)
21-25: Throw conversions look correct; consider reducing echoed request body ininvalid_json_body.The
throw simpleError(...)updates align withsimpleError(...): never. Forinvalid_json_body, including the rawbodyin the error payload may unnecessarily reflect user input (email/org_id) back to clients and/or logs.Possible adjustment (keep only schema issues / minimal context)
if (!parsedBodyResult.success) { - throw simpleError('invalid_json_body', 'Invalid json body', { body, parsedBodyResult }) + throw simpleError('invalid_json_body', 'Invalid json body', { issues: parsedBodyResult.error?.issues }) }Also applies to: 37-43, 53-55, 68-72
supabase/functions/_backend/private/stripe_portal.ts (1)
21-22: Consider: Multiple failure modes share the same error message.Lines 22, 30, 39, and 44 all return
'not_authorize'with message'Not authorize'. This is a pre-existing pattern, but distinguishing these cases (e.g.,'missing_authorization','invalid_user','org_not_found','insufficient_rights') would aid debugging.Also applies to: 29-30, 38-39, 43-44
supabase/functions/_backend/private/create_device.ts (1)
57-68: Consider applying the same pattern toquickErrorcalls for consistency.The
quickErrorfunction also has aneverreturn type (assimpleErrordelegates to it), but lines 58 and 67 still usereturn quickError(...). While outside the scope of this PR, you may want to address these in a follow-up for full consistency.supabase/functions/_backend/private/upload_link.ts (1)
28-56: Consider applying the same pattern toquickErrorcalls for consistency.Lines 29, 43, and 55 use
return quickError(...), butquickErroralso has aneverreturn type. For full consistency with the PR's objective, consider changing these tothrow quickError(...)in a follow-up.supabase/functions/_backend/private/delete_failed_version.ts (1)
26-48: Consider updatingquickErrorcalls for consistency.The
quickErrorfunction also returnsnever(throws internally), so lines 27, 31, 40, 44, 47 usingreturn quickError(...)have the same semantic issue this PR addresses forsimpleError. Consider updating these tothrow quickError(...)for consistency.supabase/functions/_backend/files/preview.ts (1)
321-324: Consider passing the original error as the cause parameter.The caught
erroris logged but not passed tosimpleError(). This may lose useful debugging context for upstream error handlers or monitoring.Proposed fix
catch (error) { cloudlog({ requestId: c.get('requestId'), message: 'failed to serve preview file', error, s3_path: manifestEntry.s3_path }) - throw simpleError('preview_failed', 'Failed to serve preview file') + throw simpleError('preview_failed', 'Failed to serve preview file', {}, error) }supabase/functions/_backend/private/invite_new_user_to_org.ts (2)
36-96: Inconsistent error handling invalidateInvite.This function has a mixed pattern: line 40 now
throws on validation failure, but lines 47-48, 64-66, 75-77, 81-83, and 92-94 still return error objects. This inconsistency makes the function harder to reason about—callers must handle both thrown exceptions and returned error objects.Consider converting all error paths to
throwfor consistency with the PR's objective.
102-108: Fragile error detection relies on missinginviteCreatorUser.The check
!res.inviteCreatorUserconflates multiple failure modes (user exists, org not found, auth failure, etc.) into a single condition. Combined with the mixed throw/return pattern invalidateInvite, this makes error handling unclear.If
validateInvitethrew on all errors (as suggested above), this block could be simplified to only handle the success path.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (39)
supabase/functions/_backend/files/files.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/private/events.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/utils/supabase.ts
🧰 Additional context used
📓 Path-based instructions (7)
supabase/functions/_backend/**/*.{ts,js}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
supabase/functions/_backend/**/*.{ts,js}: Backend code must be placed insupabase/functions/_backend/as shared code deployed to Cloudflare Workers (API/Plugin/Files workers), Supabase Edge Functions, and other platforms
UsecreateHonofromutils/hono.tsfor all Hono framework application initialization and routing
All database operations must usegetPgClient()orgetDrizzleClient()fromutils/pg.tsfor PostgreSQL access during active migration to Cloudflare D1
All Hono endpoint handlers must acceptContext<MiddlewareKeyVariables>and usec.get('requestId'),c.get('apikey'), andc.get('auth')for request context
Use structured logging withcloudlog({ requestId: c.get('requestId'), message: '...' })for all backend logging
UsemiddlewareAPISecretfor internal API endpoints andmiddlewareKeyfor external API keys; validate againstowner_orgin theapikeystable
Checkc.get('auth')?.authTypeto determine authentication type ('apikey' vs 'jwt') in backend endpoints
Use Drizzle ORM query patterns withschemafrompostgress_schema.tsfor all database operations; usealiasV2()for self-joins or multiple table references
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
supabase/functions/**/*.{ts,js}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Backend ESLint must pass before commit; run
bun lint:backendfor backend files
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
**/*.{vue,ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Run
bun lintto lint Vue, TypeScript, and JavaScript files; usebun lint:fixto auto-fix issues
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use single quotes and no semicolons per @antfu/eslint-config rules
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
supabase/functions/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
supabase/functions/**/*.ts: Never use the Supabase admin SDK with service key for user-facing APIs; always use client SDK with user authentication to enforce RLS policies. Admin SDK should only be used for internal operations (triggers, CRON jobs, etc.)
When admin access is unavoidable for a user-facing endpoint, sanitize all user inputs carefully to prevent PostgREST query injection
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
**/*.{ts,tsx,js,jsx,vue}
📄 CodeRabbit inference engine (AGENTS.md)
Run
bun lintor lint/format command before validating any backend or frontend task to ensure consistent formatting
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
supabase/functions/_backend/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Place core backend logic in supabase/functions/_backend/ with plugins, private, public, triggers, and utils subdirectories
Files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/files/files.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/triggers/on_manifest_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/triggers/on_channel_update.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/triggers/cron_stat_org.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/files/preview.tssupabase/functions/_backend/private/latency.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/private/delete_failed_version.tssupabase/functions/_backend/triggers/on_version_create.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
🧠 Learnings (16)
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Check `c.get('auth')?.authType` to determine authentication type ('apikey' vs 'jwt') in backend endpoints
Applied to files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/private/validate_password_compliance.tssupabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/on_user_update.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/accept_invitation.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : All database operations must use `getPgClient()` or `getDrizzleClient()` from `utils/pg.ts` for PostgreSQL access during active migration to Cloudflare D1
Applied to files:
supabase/functions/_backend/private/credits.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/queue_consumer.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : All Hono endpoint handlers must accept `Context<MiddlewareKeyVariables>` and use `c.get('requestId')`, `c.get('apikey')`, and `c.get('auth')` for request context
Applied to files:
supabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/utils/hono.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Use `createHono` from `utils/hono.ts` for all Hono framework application initialization and routing
Applied to files:
supabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Use `middlewareAPISecret` for internal API endpoints and `middlewareKey` for external API keys; validate against `owner_org` in the `apikeys` table
Applied to files:
supabase/functions/_backend/utils/hono_middleware_stripe.tssupabase/functions/_backend/private/set_org_email.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/invite_new_user_to_org.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Use structured logging with `cloudlog({ requestId: c.get('requestId'), message: '...' })` for all backend logging
Applied to files:
supabase/functions/_backend/triggers/cron_clear_versions.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/cron_sync_sub.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/private/download_link.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/private/stripe_portal.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/private/stripe_checkout.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2026-01-10T04:55:25.264Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T04:55:25.264Z
Learning: Applies to supabase/functions/_backend/**/*.ts : Place core backend logic in supabase/functions/_backend/ with plugins, private, public, triggers, and utils subdirectories
Applied to files:
supabase/functions/_backend/private/create_device.tssupabase/functions/_backend/triggers/on_app_create.tssupabase/functions/_backend/triggers/on_deploy_history_create.tssupabase/functions/_backend/private/store_top.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/triggers/stripe_event.tssupabase/functions/_backend/triggers/credit_usage_alerts.tssupabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/plugin_parser.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/triggers/cron_stat_app.tssupabase/functions/_backend/triggers/queue_consumer.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-24T14:11:10.256Z
Learnt from: WcaleNieWolny
Repo: Cap-go/capgo PR: 1300
File: supabase/migrations/20251224103713_2fa_enforcement.sql:409-539
Timestamp: 2025-12-24T14:11:10.256Z
Learning: In supabase/migrations for get_orgs_v6 and get_orgs_v7: The inner functions with user_id parameter (get_orgs_v6(uuid) and get_orgs_v7(uuid)) should NOT be granted to anon/authenticated roles as this allows any user to query other users' organizations; only the no-argument wrapper functions should be public as they perform authentication checks.
Applied to files:
supabase/functions/_backend/triggers/on_organization_create.tssupabase/functions/_backend/private/set_org_email.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to cloudflare_workers/files/index.ts : Files Worker (port 8789) handles file upload/download operations
Applied to files:
supabase/functions/_backend/files/files.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Use shared backend code from `supabase/functions/_backend/` across all deployment platforms; never create platform-specific implementations outside this directory
Applied to files:
supabase/functions/_backend/triggers/on_deploy_history_create.ts
📚 Learning: 2025-10-14T17:30:06.380Z
Learnt from: WcaleNieWolny
Repo: Cap-go/capgo PR: 1222
File: supabase/migrations/20251014135440_add_cron_sync_sub.sql:78-86
Timestamp: 2025-10-14T17:30:06.380Z
Learning: The cron_sync_sub function will NOT be deployed on Cloudflare, so messages queued for 'cron_sync_sub' should not include function_type: 'cloudflare'.
Applied to files:
supabase/functions/_backend/triggers/cron_sync_sub.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Backend code must be placed in `supabase/functions/_backend/` as shared code deployed to Cloudflare Workers (API/Plugin/Files workers), Supabase Edge Functions, and other platforms
Applied to files:
supabase/functions/_backend/private/store_top.tssupabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/**/*.{ts,js} : Backend ESLint must pass before commit; run `bun lint:backend` for backend files
Applied to files:
supabase/functions/_backend/utils/hono.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/private/log_as.tssupabase/functions/_backend/private/events.ts
📚 Learning: 2025-12-23T02:53:12.055Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T02:53:12.055Z
Learning: Applies to supabase/functions/_backend/**/*.{ts,js} : Use Drizzle ORM query patterns with `schema` from `postgress_schema.ts` for all database operations; use `aliasV2()` for self-joins or multiple table references
Applied to files:
supabase/functions/_backend/utils/hono.ts
📚 Learning: 2026-01-10T04:55:25.264Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T04:55:25.264Z
Learning: Applies to supabase/functions/**/*.ts : Never use the Supabase admin SDK with service key for user-facing APIs; always use client SDK with user authentication to enforce RLS policies. Admin SDK should only be used for internal operations (triggers, CRON jobs, etc.)
Applied to files:
supabase/functions/_backend/private/devices.tssupabase/functions/_backend/utils/supabase.tssupabase/functions/_backend/private/admin_stats.tssupabase/functions/_backend/private/upload_link.tssupabase/functions/_backend/private/stats.tssupabase/functions/_backend/private/log_as.ts
📚 Learning: 2026-01-10T04:55:25.264Z
Learnt from: CR
Repo: Cap-go/capgo PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-10T04:55:25.264Z
Learning: Applies to supabase/functions/**/*.ts : When admin access is unavoidable for a user-facing endpoint, sanitize all user inputs carefully to prevent PostgREST query injection
Applied to files:
supabase/functions/_backend/private/log_as.ts
🧬 Code graph analysis (38)
supabase/functions/_backend/private/credits.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/validate_password_compliance.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/cron_clear_versions.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/create_device.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/on_app_create.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/on_organization_create.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/files/files.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/set_org_email.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/on_manifest_create.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/on_deploy_history_create.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/cron_sync_sub.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/store_top.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/on_channel_update.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/utils/hono.ts (1)
supabase/functions/_backend/utils/logging.ts (1)
cloudlog(3-15)
supabase/functions/_backend/triggers/stripe_event.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/credit_usage_alerts.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/cron_stat_org.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/invite_new_user_to_org.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/logging.ts (1)
cloudlog(3-15)
supabase/functions/_backend/files/preview.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/logging.ts (1)
cloudlog(3-15)
supabase/functions/_backend/private/latency.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/devices.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/utils/plugin_parser.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/utils.ts (1)
fixSemver(55-66)
supabase/functions/_backend/private/download_link.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/downloadUrl.ts (1)
getBundleUrl(16-48)
supabase/functions/_backend/triggers/cron_email.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/stripe_portal.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/supabase.ts (2)
supabaseClient(38-48)hasOrgRight(287-304)
supabase/functions/_backend/utils/supabase.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/admin_stats.ts (3)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/supabase.ts (1)
isAdmin(563-571)supabase/functions/_backend/utils/logging.ts (1)
cloudlog(3-15)
supabase/functions/_backend/triggers/on_user_update.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/stripe_checkout.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/supabase.ts (1)
supabaseClient(38-48)
supabase/functions/_backend/private/delete_failed_version.ts (3)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/version.ts (1)
version(1-1)supabase/functions/_backend/utils/s3.ts (1)
s3(146-153)
supabase/functions/_backend/triggers/on_version_create.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/cron_stat_app.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/triggers/queue_consumer.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/upload_link.ts (2)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)supabase/functions/_backend/utils/s3.ts (1)
s3(146-153)
supabase/functions/_backend/private/stats.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/log_as.ts (2)
supabase/functions/_backend/utils/hono.ts (2)
simpleError(247-249)parseBody(251-262)supabase/functions/_backend/utils/supabase.ts (2)
supabaseAdmin(75-84)isAdmin(563-571)
supabase/functions/_backend/private/accept_invitation.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
supabase/functions/_backend/private/events.ts (1)
supabase/functions/_backend/utils/hono.ts (1)
simpleError(247-249)
Fixed grammatical error in error codes across 5 files in private/. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|


Summary
Fixed inconsistent error handling pattern where
simpleError()calls were usingreturninstead ofthrow. SincesimpleError()returnsnevertype (it throws HTTPException internally), all callers should usethrowfor correct error handling semantics.Test plan
bun lint:backendpasses with no errorsbun test:backendpasses with 127 unit tests passing (integration tests require running backend)Checklist
bun run lint:backend🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.