fix: logo URL validation shows cryptic error instead of meaningful message #213

Closed
opened 2026-04-05 17:02:41 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @shreyaspapi on 2/23/2026

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Summary

Fixes #2325

  • Replaced z.union([z.literal(""), z.string().superRefine(...)]) with a single z.string().superRefine(...) that handles the empty string case internally
  • Applied the same fix to both client-side (AuthPageBrandingForm.tsx) and server-side (upsertLoginPageBranding.ts) validation schemas

Problem

When entering a logo URL that fails validation (e.g., the server doesn't return an image/* content-type), users see the cryptic error:

Too big: expected string to have <=0 characters

This happens because Zod's z.union tries all branches when one fails. The first branch (z.literal("")) expects an empty string, so its error message about <=0 characters gets surfaced instead of the actual validation error from the superRefine branch.

Fix

Move the empty string check inside the superRefine callback as an early return. This eliminates the z.union entirely, so validation errors (invalid URL, non-image content-type, network errors, etc.) are always reported directly to the user.

How to test?

All existing validation cases are preserved:

  • Empty string (no logo) -> passes
  • Invalid URL -> "Must be a valid URL"
  • URL returns non-200 -> "Failed to load image..."
  • URL doesn't serve image content-type -> "URL does not point to an image..."
  • Network/fetch error -> specific error message
  • Enterprise local path validation -> unchanged
*Originally created by @shreyaspapi on 2/23/2026* ## Community Contribution License Agreement By creating this pull request, I grant the project maintainers an unlimited, perpetual license to use, modify, and redistribute these contributions under any terms they choose, including both the AGPLv3 and the Fossorial Commercial license terms. I represent that I have the right to grant this license for all contributed content. ## Summary Fixes #2325 - Replaced `z.union([z.literal(""), z.string().superRefine(...)])` with a single `z.string().superRefine(...)` that handles the empty string case internally - Applied the same fix to both client-side (`AuthPageBrandingForm.tsx`) and server-side (`upsertLoginPageBranding.ts`) validation schemas ## Problem When entering a logo URL that fails validation (e.g., the server doesn't return an `image/*` content-type), users see the cryptic error: > `Too big: expected string to have <=0 characters` This happens because Zod's `z.union` tries all branches when one fails. The first branch (`z.literal("")`) expects an empty string, so its error message about `<=0 characters` gets surfaced instead of the actual validation error from the `superRefine` branch. ## Fix Move the empty string check inside the `superRefine` callback as an early return. This eliminates the `z.union` entirely, so validation errors (invalid URL, non-image content-type, network errors, etc.) are always reported directly to the user. ## How to test? All existing validation cases are preserved: - Empty string (no logo) -> passes - Invalid URL -> `"Must be a valid URL"` - URL returns non-200 -> `"Failed to load image..."` - URL doesn't serve image content-type -> `"URL does not point to an image..."` - Network/fetch error -> specific error message - Enterprise local path validation -> unchanged
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/pangolin#213