Skip to content

feat(drizzle): include collection and global slugs in validation errors - #15147

Merged
AlessioGr merged 9 commits into
mainfrom
feat/drizzle-validation-error-slugs
Jan 9, 2026
Merged

AlessioGr merged 9 commits into
mainfrom
feat/drizzle-validation-error-slugs

Conversation

@AlessioGr

@AlessioGr AlessioGr commented Jan 9, 2026 •

Copy link
Copy Markdown
Member

Unique constraint ValidationErrors now include data.collection or data.global for better error context.

Changes:

  • Added optional collectionSlug and globalSlug parameters to upsertRow
  • Passed slugs through to handleUpsertError → ValidationError
  • Updated all callers: create, updateOne, updateMany, updateJobs, createGlobal, updateGlobal, createVersion, updateVersion, createGlobalVersion, updateGlobalVersion, fetchAndResave
  • Updated test to verify error.data.collection is populated

@AlessioGr
AlessioGr changed the base branch from main to fix/drizzle-validation-errors-optimized January 9, 2026 05:02
Fixes #14495

The SDK now throws a proper `PayloadSDKError` class on failed API
requests instead of either returning undefined or a generic `Error`.
Error handling is centralized in the `request()` method, which adds
error handling for operations where it was previously missing (like
`create`, `update`, `delete`, `find`, etc.).

**Changes:**
- Added `PayloadSDKError` class with `status`, `errors`, `response`, and
`message` properties
- Centralized error handling in `request()` - all operations now
properly throw on failed responses. Previously, some operations (like
`findByID`) just threw a generic Error that did not explain what
actually went wrong and some operations (like `create`) did not throw an
error at all and simply returned undefined.
- Lots of new int tests

**Usage:**
```ts
import { PayloadSDKError } from '@payloadcms/sdk'

try {
  await sdk.create({ collection: 'posts', data: { ... } })
} catch (err) {
  if (err instanceof PayloadSDKError) {
    console.log(err.status)  // 400
    console.log(err.errors)  // [{ name: 'ValidationError', message: '...', data: {...} }]
  }
}
```
@github-actions

github-actions Bot commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖
This PR introduced no changes to the esbuild bundle! 🙌

Base automatically changed from fix/drizzle-validation-errors-optimized to main January 9, 2026 07:57
@AlessioGr
AlessioGr marked this pull request as ready for review January 9, 2026 17:08
@AlessioGr
AlessioGr enabled auto-merge (squash) January 9, 2026 17:22
r1tsuu
r1tsuu previously approved these changes Jan 9, 2026
@AlessioGr
AlessioGr merged commit 910d274 into main Jan 9, 2026
@AlessioGr
AlessioGr deleted the feat/drizzle-validation-error-slugs branch January 9, 2026 18:22
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.71.0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants