workerd icon indicating copy to clipboard operation
workerd copied to clipboard

type D1Result problem

Open qiaoshouzi opened this issue 2 years ago • 3 comments

According to the documentation, the 'success' field under D1Result should be of type boolean, but currently, it is set to true. https://developers.cloudflare.com/d1/platform/client-api/#return-object

declare interface D1Result<T = unknown> {
  results: T[];
  success: true;
  meta: any;
  error?: never;
}

qiaoshouzi avatar Jul 31 '23 08:07 qiaoshouzi

Hey! 👋 Thanks for reporting this. It looks like the D1 Worker API will always throw an error if success is false... https://github.com/cloudflare/workerd/blob/8a06df3ee110e47cfc40e5b410f8805efdb61da6/src/cloudflare/internal/d1-api.ts#L116-L120 ...so D1Results you see, will always have success: true set. @geelen, can you confirm the docs are incorrect here?

mrbbot avatar Jul 31 '23 13:07 mrbbot

Hey all, I help maintain a D1 compatible database sdk, and I found this issue while trying to update my typing. Looks like the docs are right? Does that make this a bug?

joewagner avatar Oct 31 '23 09:10 joewagner

The code looks wrong to me, return an error with plain text error message makes it hard for us to handle the different errors returned from D1.

I agree the doc is right and this should be mark as a bug.

chunlea avatar Apr 15 '24 07:04 chunlea