Skip to content

fix: show error messages in god-mode instance setup form#8974

Open
chkn wants to merge 1 commit intomakeplane:previewfrom
chkn:fix/god-mode-setup-error-display
Open

fix: show error messages in god-mode instance setup form#8974
chkn wants to merge 1 commit intomakeplane:previewfrom
chkn:fix/god-mode-setup-error-display

Conversation

@chkn
Copy link
Copy Markdown

@chkn chkn commented Apr 29, 2026

Summary

  • The god-mode /god-mode/ instance setup form silently swallowed all backend errors, leaving users staring at the same form with query params in the URL but no visible message
  • Root cause: the form's local EErrorCodes enum used readable string values ("INSTANCE_NOT_CONFIGURED", "INVALID_EMAIL", etc.) but the backend sends numeric error codes (5155, 5160, etc.) — the switch statement never matched
  • The sign-in form already had the correct pattern (authErrorHandler + AuthBanner) — the setup form is now aligned with it
  • Also adds INSTANCE_NOT_CONFIGURED (5000) and PASSWORD_TOO_WEAK (5021) to EAdminAuthErrorCodes, which were missing despite being sent by the admin sign-up endpoint

Files changed

  • packages/constants/src/auth/index.ts — add INSTANCE_NOT_CONFIGURED and PASSWORD_TOO_WEAK to EAdminAuthErrorCodes
  • apps/admin/app/(all)/(home)/auth-helpers.tsx — add messages and banner handling for those two codes
  • apps/admin/components/instance/setup-form.tsx — replace broken switch-based error logic with authErrorHandler + AuthBanner

Test plan

  • Navigate to /god-mode/ on a fresh instance (setup not done)
  • Submit the form with a weak password — banner should appear: "Your password is too weak…"
  • Submit with a mismatched confirm password — Continue button stays disabled
  • Submit with a valid strong password — form posts and instance is configured
  • On an already-configured instance, hitting the sign-up endpoint directly should show "Admin already exists" banner

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for two additional error scenarios in the admin authentication process.
  • Bug Fixes

    • Improved error messaging clarity and consistency across the admin setup form.
    • Enhanced error display presentation in the authentication interface.

The setup form's local EErrorCodes enum used string values like
"INSTANCE_NOT_CONFIGURED" but the backend sends numeric error codes
(e.g. 5155). The switch statement never matched, silently swallowing
all errors and leaving the user staring at the same form with no
feedback.

Aligns the setup form with the sign-in form's working pattern:
authErrorHandler + AuthBanner. Also adds INSTANCE_NOT_CONFIGURED
and PASSWORD_TOO_WEAK to EAdminAuthErrorCodes, which were missing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chkn chkn requested a review from sriramveeraghanta as a code owner April 29, 2026 16:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

The pull request adds two new admin authentication error codes (INSTANCE_NOT_CONFIGURED and PASSWORD_TOO_WEAK) to a centralized error handling system, and refactors the setup form component to use the shared auth error handler instead of maintaining local error-handling logic.

Changes

Cohort / File(s) Summary
Error Code Constants
packages/constants/src/auth/index.ts
Introduces two new enum members to EAdminAuthErrorCodes for instance-not-configured ("5000") and password-too-weak ("5021") conditions.
Auth Error Mapping
apps/admin/app/(all)/(home)/auth-helpers.tsx
Registers the two new error codes in errorCodeMessages with titles and user-facing messages, and includes them in bannerAlertErrorCodes to route them as BANNER_ALERT responses.
Setup Form Refactoring
apps/admin/components/instance/setup-form.tsx
Replaces local error-code switch logic with centralized authErrorHandler, removes legacy conditional error banner and per-field validation messages, integrates AuthBanner component for unified error display, and simplifies form submit disabling logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Two error codes hopped into the fold,
From shadow to center, a pattern behold!
The setup form danced with the handler so grand,
Centralized warnings now hand-in-hand,
One auth to rule them—thump thump—all planned!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description provides detailed context, root cause analysis, file changes, and test scenarios; however, the Type of Change checkbox template section is not completed as required by the description template. Complete the 'Type of Change' section by marking the appropriate checkbox(es) (likely 'Bug fix' and/or 'Code refactoring') to fully align with the template requirements.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and specifically describes the main fix: displaying error messages in the god-mode instance setup form, which matches the core problem and solution in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (1)
apps/admin/components/instance/setup-form.tsx (1)

54-85: ⚠️ Potential issue | 🟠 Major

Telemetry opt-out from query params can’t be applied.

is_telemetry_enabled=False gets parsed to false at Line 54, but Line 84 only updates form state when the value is truthy. That leaves telemetry enabled (true) even when the URL explicitly says False.

💡 Proposed fix
-  const isTelemetryEnabledParam = searchParams?.get("is_telemetry_enabled") === "True";
+  const isTelemetryEnabledParam = searchParams?.get("is_telemetry_enabled");

@@
-    if (isTelemetryEnabledParam) setFormData((prev) => ({ ...prev, is_telemetry_enabled: isTelemetryEnabledParam }));
+    if (isTelemetryEnabledParam !== null)
+      setFormData((prev) => ({ ...prev, is_telemetry_enabled: isTelemetryEnabledParam === "True" }));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/admin/components/instance/setup-form.tsx` around lines 54 - 85,
is_telemetry_enabled from query params is turned into a boolean at declaration
so the effect's truthy check skips explicit "False"; change the parsing to
capture the raw string and apply the boolean conversion only when the param
exists: replace the current isTelemetryEnabledParam with a raw value (e.g.
isTelemetryEnabledParamRaw = searchParams?.get("is_telemetry_enabled")), then in
the useEffect for initializing formData check if isTelemetryEnabledParamRaw !==
null/undefined and call setFormData(prev => ({ ...prev, is_telemetry_enabled:
isTelemetryEnabledParamRaw === "True" })); update any references from
isTelemetryEnabledParam to the new raw variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/admin/components/instance/setup-form.tsx`:
- Around line 87-92: The useEffect watching errorCode only sets errorInfo when
authErrorHandler(errorCode) returns a detail, but it never clears stale state;
update the effect in setup-form.tsx so that inside the effect you call
authErrorHandler(errorCode as EAdminAuthErrorCodes) and if it returns a detail
setErrorInfo(detail), otherwise call setErrorInfo(undefined) (also handle the
case when errorCode is falsy by clearing via setErrorInfo(undefined)),
referencing the existing useEffect, errorCode, authErrorHandler, and
setErrorInfo symbols to locate and change the logic.

---

Outside diff comments:
In `@apps/admin/components/instance/setup-form.tsx`:
- Around line 54-85: is_telemetry_enabled from query params is turned into a
boolean at declaration so the effect's truthy check skips explicit "False";
change the parsing to capture the raw string and apply the boolean conversion
only when the param exists: replace the current isTelemetryEnabledParam with a
raw value (e.g. isTelemetryEnabledParamRaw =
searchParams?.get("is_telemetry_enabled")), then in the useEffect for
initializing formData check if isTelemetryEnabledParamRaw !== null/undefined and
call setFormData(prev => ({ ...prev, is_telemetry_enabled:
isTelemetryEnabledParamRaw === "True" })); update any references from
isTelemetryEnabledParam to the new raw variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f000675-0a55-4ca4-ac17-ac1f99442d12

📥 Commits

Reviewing files that changed from the base of the PR and between a62fe8a and f77263d.

📒 Files selected for processing (3)
  • apps/admin/app/(all)/(home)/auth-helpers.tsx
  • apps/admin/components/instance/setup-form.tsx
  • packages/constants/src/auth/index.ts

Comment on lines +87 to +92
useEffect(() => {
if (errorCode) {
const errorDetail = authErrorHandler(errorCode as EAdminAuthErrorCodes);
if (errorDetail) setErrorInfo(errorDetail);
}
}, [errorCode]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clear stale banner state when error_code is absent or unrecognized.

Current logic only sets state on recognized codes; it does not reset previous errors when error_code is removed/changed. That can leave an outdated banner visible.

💡 Proposed fix
   useEffect(() => {
-    if (errorCode) {
-      const errorDetail = authErrorHandler(errorCode as EAdminAuthErrorCodes);
-      if (errorDetail) setErrorInfo(errorDetail);
-    }
+    setErrorInfo(errorCode ? authErrorHandler(errorCode as EAdminAuthErrorCodes) : undefined);
   }, [errorCode]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (errorCode) {
const errorDetail = authErrorHandler(errorCode as EAdminAuthErrorCodes);
if (errorDetail) setErrorInfo(errorDetail);
}
}, [errorCode]);
useEffect(() => {
setErrorInfo(errorCode ? authErrorHandler(errorCode as EAdminAuthErrorCodes) : undefined);
}, [errorCode]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/admin/components/instance/setup-form.tsx` around lines 87 - 92, The
useEffect watching errorCode only sets errorInfo when
authErrorHandler(errorCode) returns a detail, but it never clears stale state;
update the effect in setup-form.tsx so that inside the effect you call
authErrorHandler(errorCode as EAdminAuthErrorCodes) and if it returns a detail
setErrorInfo(detail), otherwise call setErrorInfo(undefined) (also handle the
case when errorCode is falsy by clearing via setErrorInfo(undefined)),
referencing the existing useEffect, errorCode, authErrorHandler, and
setErrorInfo symbols to locate and change the logic.

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.

1 participant