Skip to content

feat: implement explicit custom error messages for theme validation in Zod API schemas #5698#5760

Open
attardekhushi78-cpu wants to merge 2 commits into
JhaSourav07:mainfrom
attardekhushi78-cpu:feat/zod-schema-errors
Open

feat: implement explicit custom error messages for theme validation in Zod API schemas #5698#5760
attardekhushi78-cpu wants to merge 2 commits into
JhaSourav07:mainfrom
attardekhushi78-cpu:feat/zod-schema-errors

Conversation

@attardekhushi78-cpu

Copy link
Copy Markdown
Contributor

💡 Related Issue

Closes #5698

📝 Description

Refactored the underlying Zod validation parameters within baseStreakParamsSchema (theme, bg, text, and accent) to improve backend API Developer Experience (DX).

Previously, when users passed invalid theme selections or malformed/incorrect hex codes, the schemas utilized immediate .transform() blocks to silently fall back to undefined or general structures. This behavior could obscure debugging info or trigger misleading errors further downstream.

🛠️ Changes Implemented

  • Added strict structural .refine() validation blocks to theme, bg, text, and accent fields inside lib/validations.ts prior to their transformations.
  • Introduced explicit, developer-friendly validation feedback strings (e.g., "Invalid background hex color format. Expected a valid 3, 4, 6, or 8-digit hex string.").
  • Preserved all original array tracking, trimming, and sanitization pipelines inside the subsequent .transform() structures to maintain backward compatibility with existing tests and rendering handlers.

🧪 How This Was Tested

  • Launched the local Next.js development workspace (npm run dev).
  • Tested the streak parameters validation endpoint with invalid hex color variations and unknown theme query variables (e.g., ?bg=invalidHexValue).
  • Verified that the system safely catches the Zod parsing exceptions and correctly reflects the targeted error messages in the API response rather than failing silently.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@Openops-CommitVerse is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @attardekhushi78-cpu, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@Aamod-Dev Aamod-Dev added level:intermediate Moderate complexity tasks mentor:Aamod007 type:bug Something isn't working as expected labels Jun 15, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for tightening the streak-parameter validation. I reviewed the PR description, linked issue #5698, the failing CI log, and the actual diff before labeling.

Labels applied:

  • level:intermediate: this is a single-file change in lib/validations.ts, but it touches the core baseStreakParamsSchema path for theme, bg, text, and accent and affects several downstream tests and API behaviors in one go.
  • type:bug: the PR is explicitly fixing validation behavior, and the current failure is a behavioral regression in the streak route tests.

I am requesting changes because the new .refine() checks change invalid color inputs from graceful fallback to hard validation failures, and the existing streak route tests still expect 200 responses for those cases.

What is failing:

  • app/api/streak/route.test.ts now receives 400 for invalid bg, text, and accent inputs, but the tests still expect 200.
  • The theme validation message was also changed from Invalid theme. Supported themes: to Invalid theme selection. Supported themes:, so the expectations in lib/validations.test.ts, lib/validations.streakParamsSchema.test.ts, and lib/validations.theme-contrast.test.ts no longer match.

How to fix it:

  1. Decide whether the new behavior should be a hard validation error or a graceful fallback.
  2. If hard errors are intended, update the affected tests to expect 400 and assert the new error messages.
  3. If graceful fallback is intended, keep the new error messages for developer clarity, but move the invalid-color handling back into the transforms so the API still returns 200 with sanitized defaults.
  4. Re-run the streak and validations test files after the behavior is aligned.

Once the schema behavior and the tests agree again, this can move forward cleanly.

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is still blocked, so I can’t approve it yet. The new .refine() checks in lib/validations.ts are a meaningful DX improvement, but the PR needs the failing checks cleared and the updated validation behavior verified end-to-end before we move it forward.

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like the clearer validation messages, but the PR is still blocked and needs a clean pass after the schema changes. Please clear the blocker and add a focused test showing lib/validations.ts returns the new theme/background errors without breaking the existing fallback behavior.

@github-actions github-actions Bot added type:feature New features, additions, or enhancements and removed type:bug Something isn't working as expected labels Jun 15, 2026
@Aamod-Dev Aamod-Dev added level:beginner Small changes Usually isolated fixes or simple UI/text updates. quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. labels Jun 18, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Difficulty: beginner – Implements explicit custom error messages for theme validation in Zod API schemas (#5698).

Quality: clean – Better UX.

Type: feature – Error messaging.

Good UX improvement!

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

This PR cannot be approved in its current state due to blocking issues (status:blocked label, merge conflicts, needs-rebase label, and/or failing CI checks). Please resolve the blocking issues and re-request review.

Once unblocked, I'm happy to re-review! 💚

@Aamod-Dev Aamod-Dev added GSSoC 2026 feature A completely new feature or major addition to the project. labels Jun 21, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Improving the API Developer Experience with explicit Zod validation messages is a very good refactor. It makes debugging parameter errors much easier. However, the PR is marked as blocked. Please resolve the blocking issues so we can get this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A completely new feature or major addition to the project. GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. status:blocked This PR is blocked due to a failing CI check. type:feature New features, additions, or enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement explicit custom error messages for theme validation in Zod API schemas

4 participants