Skip to content

TypeError: The "payload" argument must be of type object. Received null #26178

@Kirisamememe

Description

@Kirisamememe

Bug description

I encountered the following error earlier.

{
  slug: '',
  title: '',
  description: '',
  adminOnly: false,
  permissionLevel: 3,
  authorNote: '',
  json: {
    title: 'Title',
    body: 'This is a demo. You can edit it.',
    isActive: true,
    like: 5431,
    tag: [ 'food', 'travel', 'technology' ],
    block: { title: 'Block', body: 'This is a block.' },
    publishedAt: '2025-01-25T03:51:38.433Z'
  }
}
 ⨯ TypeError: The "payload" argument must be of type object. Received null
    at dbExceptionHandler (src/exception-handling/exception-handler-db.ts:2:10)
    at async JsonContentService.create (src/services/json-content-service.ts:119:11)
    at async createJsonContent (src/app/[locale]/admin/(main-contents)/json-content/_actions/create.ts:11:14)
  1 | export const dbExceptionHandler = (error: unknown) => {
> 2 |   console.log(error)
    |          ^
  3 |   return null
  4 | } {
  code: 'ERR_INVALID_ARG_TYPE',
  digest: '2836743208'
}

The cause is here, slug is optional, but it has a unique constraint. The error occurred because there was one record with an empty string '' for slug.

model JsonContent {
  id              Int     @id @default(autoincrement())
  slug            String? @unique
  
  //...
}

Of course, this is entirely my mistake. I am responsible.
Prisma is not at fault.

However, please let me say this.

What the heck is "TypeError: The "payload" argument must be of type object. Received null"?

If it's a unique constraint violation, please tell me that honestly. Prisma used to tell me that before.
Why did it suddenly become such a strange error message?

I really love Prisma.
I want to know why I got such an error message.

How to reproduce

It might be reproducible if you cause a unique constraint violation.
I am implementing it like this:

// repository class
createYourData(
    operatorId: number,
    values: z.infer<typeof yourSchema>
) {
  return prisma.someTable.create({
    data: {
	      // your data
    }
  })
}
// service class
  async create(operatorId: number, values: z.infer<typeof yourSchema>) {
    return await this._yourRepository.create(operatorId, values).catch(dbExceptionHandler)
  }
export const dbExceptionHandler = (error: unknown) => {
  console.error(error)
  return null
}

Expected behavior

No response

Prisma information

model JsonContent {
  id              Int     @id @default(autoincrement())
  slug            String? @unique

  //...
}

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 22.13.0

Prisma Version

6.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions