Skip to content

error message/format with the new rust-free prisma query engine #28281

Open

Description

@0xb4lamx

Bug description

the new prisma rust free engine seems to return slight different error.meta structure!

no more target property? but a driverAdapterError:

Image

I think the docs needs to be updated accordingly!

with a long confusing message error:

"\nInvalid `t=Object.create()` invocation in\n/zzzzz/mono/node_modules/.prisma/client/runtime/client.js:26:2556\n\n  23 Note that ${s.bold(\"include\")} statements only accept relation fields.`,a})}function Vd(e,t,r){let n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();if(n){let i=n.getField(\"omit\")?.value.asObject();if(i){qd(e,t,i);return}if(n.hasField(\"select\")){Ud(e,t);return}}if(r?.[Le(e.outputType.name)]){jd(e,t);return}t.addErrorMessage(()=>`Unknown field at \"${e.selectionPath.join(\".\")} selection\"`)}function qd(e,t,r){r.removeAllFields();for(let n of e.outputType.fields)r.addSuggestion(new de(n.name,\"false\"));t.addErrorMessage(n=>`The ${n.red(\"omit\")} statement includes every field of the model ${n.bold(e.outputType.name)}. At least one field must be included in the result`)}function Ud(e,t){let r=e.outputType,n=t.arguments.getDeepSelectionParent(e.selectionPath)?.value,i=n?.isEmpty()??!1;n&&(n.removeAllFields(),ua(n,r)),t.addErrorMessage(o=>i?`The ${o.red(\"`select`\")} statement for type ${o.bold(r.name)} must not be empty. ${ur(o)}`:`The ${o.red(\"`select`\")} statement for type ${o.bold(r.name)} needs ${o.bold(\"at least one truthy value\")}.`)}function jd(e,t){let r=new cr;for(let i of e.outputType.fields)i.isRelation||r.addField(i.name,\"false\");let n=new de(\"omit\",r).makeRequired();if(e.selectionPath.length===0)t.arguments.addSuggestion(n);else{let[i,o]=vt(e.selectionPath),a=t.arguments.getDeepSelectionParent(i)?.value.asObject()?.getField(o);if(a){let l=a?.value.asObject()??new Pt;l.addSuggestion(n),a.value=l}}t.addErrorMessage(i=>`The global ${i.red(\"omit\")} configuration excludes every field of the model ${i.bold(e.outputType.name)}. At least one field must be included in the result`)}function Bd(e,t){let r=pa(e.selectionPath,t);if(r.parentKind!==\"unknown\"){r.field.markAsError();let n=r.parent;switch(r.parentKind){case\"select\":ua(n,e.outputType);break;case\"include\":Xd(n,e.outputType);break;case\"omit\":em(n,e.outputType);break}}t.addErrorMessage(n=>{let i=[`Unknown field ${n.red(`\\`${r.fieldName}\\``)}`];return r.parentKind!==\"unknown\"&&i.push(`for ${n.bold(r.parentKind)} statement`),i.push(`on model ${n.bold(`\\`${e.outputType.name}\\``)}.`),i.push(ur(n)),i.join(\" \")})}function Qd(e,t){let r=pa(e.selectionPath,t);r.parentKind!==\"unknown\"&&r.field.value.markAsError(),t.addErrorMessage(n=>`Invalid value for selection field \\`${n.red(r.fieldName)}\\`: ${e.underlyingError}`)}function Hd(e,t){let r=e.argumentPath[0],n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();n&&(n.getField(r)?.markAsError(),tm(n,e.arguments)),t.addErrorMessage(i=>la(i,r,e.arguments.map(o=>o.name)))}function Gd(e,t){let[r,n]=vt(e.argumentPath),i=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();if(i){i.getDeepField(e.argumentPath)?.markAsError();let o=i.getDeepFieldValue(r)?.asObject();o&&da(o,e.inputType)}t.addErrorMessage(o=>la(o,n,e.inputType.fields.map(s=>s.name)))}function la(e,t,r){let n=[`Unknown argument \\`${e.red(t)}\\`.`],i=nm(t,r);return i&&n.push(`Did you mean \\`${e.green(i)}\\`?`),r.length>0&&n.push(ur(e)),n.join(\" \")}function Jd(e,t){let r;t.addErrorMessage(l=>r?.value instanceof G&&r.value.text===\"null\"?`Argument \\`${l.green(o)}\\` must not be ${l.red(\"null\")}.`:`Argument \\`${l.green(o)}\\` is missing.`);let n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();if(!n)return;let[i,o]=vt(e.argumentPath),s=new cr,a=n.getDeepFieldValue(i)?.asObject();if(a){if(r=a.getField(o),r&&a.removeField(o),e.inputTypes.length===1&&e.inputTypes[0].kind===\"object\"){for(let l of e.inputTypes[0].fields)s.addField(l.name,l.typeNames.join(\" | \"));a.addSuggestion(new de(o,s).makeRequired())}else{let l=e.inputTypes.map(ca).join(\" | \");a.addSuggestion(new de(o,l).makeRequired())}if(e.dependentArgumentPath){n.getDeepField(e.dependentArgumentPath)?.markAsError();let[,l]=vt(e.dependentArgumentPath);t.addErrorMessage(c=>`Argument \\`${c.green(o)}\\` is required because argument \\`${c.green(l)}\\` was provided.`)}}}function ca(e){return e.kind===\"list\"?`${ca(e.elementType)}[]`:e.name}function Wd(e,t){let r=e.argument.name,n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();n&&n.getDeepFieldValue(e.argumentPath)?.markAsError(),t.addErrorMessage(i=>{let o=Tn(\"or\",e.argument.typeNames.map(s=>i.green(s)));return`Argument \\`${i.bold(r)}\\`: Invalid value provided. Expected ${o}, provided ${i.red(e.inferredType)}.`})}function Kd(e,t){let r=e.argument.name,n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();n&&n.getDeepFieldValue(e.argumentPath)?.markAsError(),t.addErrorMessage(i=>{let o=[`Invalid value for argument \\`${i.bold(r)}\\``];if(e.underlyingError&&o.push(`: ${e.underlyingError}`),o.push(\".\"),e.argument.typeNames.length>0){let s=Tn(\"or\",e.argument.typeNames.map(a=>i.green(a)));o.push(` Expected ${s}.`)}return o.join(\"\")})}function zd(e,t){let r=e.argument.name,n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject(),i;if(n){let s=n.getDeepField(e.argumentPath)?.value;s?.markAsError(),s instanceof G&&(i=s.text)}t.addErrorMessage(o=>{let s=[\"Unable to fit value\"];return i&&s.push(o.red(i)),s.push(`into a 64-bit signed integer for field \\`${o.bold(r)}\\``),s.join(\" \")})}function Yd(e,t){let r=e.argumentPath[e.argumentPath.length-1],n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject();if(n){let i=n.getDeepFieldValue(e.argumentPath)?.asObject();i&&da(i,e.inputType)}t.addErrorMessage(i=>{let o=[`Argument \\`${i.bold(r)}\\` of type ${i.bold(e.inputType.name)} needs`];return e.constraints.minFieldCount===1?e.constraints.requiredFields?o.push(`${i.green(\"at least one of\")} ${Tn(\"or\",e.constraints.requiredFields.map(s=>`\\`${i.bold(s)}\\``))} arguments.`):o.push(`${i.green(\"at least one\")} argument.`):o.push(`${i.green(`at least ${e.constraints.minFieldCount}`)} arguments.`),o.push(ur(i)),o.join(\" \")})}function Zd(e,t){let r=e.argumentPath[e.argumentPath.length-1],n=t.arguments.getDeepSubSelectionValue(e.selectionPath)?.asObject(),i=[];if(n){let o=n.getDeepFieldValue(e.argumentPath)?.asObject();o&&(o.markAsError(),i=Object.keys(o.getFields()))}t.addErrorMessage(o=>{let s=[`Argument \\`${o.bold(r)}\\` of type ${o.bold(e.inputType.name)} needs`];return e.constraints.minFieldCount===1&&e.constraints.maxFieldCount==1?s.push(`${o.green(\"exactly one\")} argument,`):e.constraints.maxFieldCount==1?s.push(`${o.green(\"at most one\")} argument,`):s.push(`${o.green(`at most ${e.constraints.maxFieldCount}`)} arguments,`),s.push(`but you provided ${Tn(\"and\",i.map(a=>o.red(a)))}. Please choose`),e.constraints.maxFieldCount===1?s.push(\"one.\"):s.push(`${e.constraints.maxFieldCount}.`),s.join(\" \")})}function ua(e,t){for(let r of t.fields)e.hasField(r.name)||e.addSuggestion(new de(r.name,\"true\"))}function Xd(e,t){for(let r of t.fields)r.isRelation&&!e.hasField(r.name)&&e.addSuggestion(new de(r.name,\"true\"))}function em(e,t){for(let r of t.fields)!e.hasField(r.name)&&!r.isRelation&&e.addSuggestion(new de(r.name,\"true\"))}function tm(e,t){for(let r of t)e.hasField(r.name)||e.addSuggestion(new de(r.name,r.typeNames.join(\" | \")))}function pa(e,t){let[r,n]=vt(e),i=t.arguments.getDeepSubSelectionValue(r)?.asObject();if(!i)return{parentKind:\"unknown\",fieldName:n};let o=i.getFieldValue(\"select\")?.asObject(),s=i.getFieldValue(\"include\")?.asObject(),a=i.getFieldValue(\"omit\")?.asObject(),l=o?.getField(n);return o&&l?{parentKind:\"select\",parent:o,field:l,fieldName:n}:(l=s?.getField(n),s&&l?{parentKind:\"include\",field:l,parent:s,fieldName:n}:(l=a?.getField(n),a&&l?{parentKind:\"omit\",field:l,parent:a,fieldName:n}:{parentKind:\"unknown\",fieldName:n}))}function da(e,t){if(t.kind===\"object\")for(let r of t.fields)e.hasField(r.name)||e.addSuggestion(new de(r.name,r.typeNames.join(\" | \")))}function vt(e){let t=[...e],r=t.pop();if(!r)throw new Error(\"unexpected empty path\");return[t,r]}function ur({green:e,enabled:t}){return\"Available options are \"+(t?`listed in ${e(\"green\")}`:\"marked with ?\")+\".\"}function Tn(e,t){if(t.length===1)return t[0];let r=[...t],n=r.pop();return`${r.join(\", \")} ${e} ${n}`}var rm=3;function nm(e,t){let r=1/0,n;for(let i of t){let o=(0,aa.default)(e,i);o>rm||o<r&&(r=o,n=i)}return n}var pr=class{modelName;name;typeName;isList;isEnum;constructor(t,r,n,i,o){this.modelName=t,this.name=r,this.typeName=n,this.isList=i,this.isEnum=o}_toGraphQLInputType(){let t=this.isList?\"List\":\"\",r=this.isEnum?\"Enum\":\"\";return`${t}${r}${this.typeName}FieldRefInput<${this.modelName}>`}};function Tt(e){return e instanceof pr}var An=Symbol(),qi=new WeakMap,Ne=class{constructor(t){t===An?qi.set(this,`Prisma.${this._getName()}`):qi.set(this,`new Prisma.${this._getNamespace()}.${this._getName()}()`)}_getName(){return this.constructor.name}toString(){return qi.get(this)}},dr=class extends Ne{_getNamespace(){return\"NullTypes\"}},mr=class extends dr{#t};Ui(mr,\"DbNull\");var fr=class extends dr{#t};Ui(fr,\"JsonNull\");var gr=class extends dr{#t};Ui(gr,\"AnyNull\");var Cn={classes:{DbNull:mr,JsonNull:fr,AnyNull:gr},instances:{DbNull:new mr(An),JsonNull:new fr(An),AnyNull:new gr(An)}};function Ui(e,t){Object.defineProperty(e,\"name\",{value:t,configurable:!0})}var ma=\": \",Rn=class{constructor(t,r){this.name=t;this.value=r}hasError=!1;markAsError(){this.hasError=!0}getPrintWidth(){return this.name.length+this.value.getPrintWidth()+ma.length}write(t){let r=new Pe(this.name);this.hasError&&r.underline().setColor(t.context.colors.red),t.write(r).write(ma).write(this.value)}};var ji=class{arguments;errorMessages=[];constructor(t){this.arguments=t}write(t){t.write(this.arguments)}addErrorMessage(t){this.errorMessages.push(t)}renderAllMessages(t){return this.errorMessages.map(r=>r(t)).join(`\n  24 `)}};function At(e){return new ji(fa(e))}function fa(e){let t=new Pt;for(let[r,n]of Object.entries(e)){let i=new Rn(r,ga(n));t.addField(i)}return t}function ga(e){if(typeof e==\"string\")return new G(JSON.stringify(e));if(typeof e==\"number\"||typeof e==\"boolean\")return new G(String(e));if(typeof e==\"bigint\")return new G(`${e}n`);if(e===null)return new G(\"null\");if(e===void 0)return new G(\"undefined\");if(ht(e))return new G(`new Prisma.Decimal(\"${e.toFixed()}\")`);if(e instanceof Uint8Array)return Buffer.isBuffer(e)?new G(`Buffer.alloc(${e.byteLength})`):new G(`new Uint8Array(${e.byteLength})`);if(e instanceof Date){let t=ln(e)?e.toISOString():\"Invalid Date\";return new G(`new Date(\"${t}\")`)}return e instanceof Ne?new G(`Prisma.${e._getName()}`):Tt(e)?new G(`prisma.${Le(e.modelName)}.$fields.${e.name}`):Array.isArray(e)?im(e):typeof e==\"object\"?fa(e):new G(Object.prototype.toString.call(e))}function im(e){let t=new bt;for(let r of e)t.addItem(ga(r));return t}function Sn(e,t){let r=t===\"pretty\"?sa:vn,n=e.renderAllMessages(r),i=new Et(0,{colors:r}).write(e).toString();return{message:n,args:i}}function In({args:e,errors:t,errorFormat:r,callsite:n,originalMethod:i,clientVersion:o,globalOmit:s}){let a=At(e);for(let p of t)xn(p,a,s);let{message:l,args:c}=Sn(a,r),u=En({message:l,callsite:n,originalMethod:i,showColors:r===\"pretty\",callArguments:c});throw new X(u,{clientVersion:o})}function ve(e){return e.replace(/^./,t=>t.toLowerCase())}function ha(e,t,r){let n=ve(r);return!t.result||!(t.result.$allModels||t.result[n])?e:om({...e,...ya(t.name,e,t.result.$allModels),...ya(t.name,e,t.result[n])})}function om(e){let t=new Ee,r=(n,i)=>t.getOrCreate(n,()=>i.has(n)?[n]:(i.add(n),e[n]?e[n].needs.flatMap(o=>r(o,i)):[n]));return an(e,n=>({...n,needs:r(n.name,new Set)}))}function ya(e,t,r){return r?an(r,({needs:n,compute:i},o)=>({name:o,needs:n?Object.keys(n).filter(s=>n[s]):[],compute:sm(t,o,i)})):{}}function sm(e,t,r){let n=e?.[t]?.compute;return n?i=>r({...i,[t]:n(i)}):r}function wa(e,t){if(!t)return e;let r={...e};for(let n of Object.values(t))if(e[n.name])for(let i of n.needs)r[i]=!0;return r}function Ea(e,t){if(!t)return e;let r={...e};for(let n of Object.values(t))if(!e[n.name])for(let i of n.needs)delete r[i];return r}var kn=class{constructor(t,r){this.extension=t;this.previous=r}computedFieldsCache=new Ee;modelExtensionsCache=new Ee;queryCallbacksCache=new Ee;clientExtensions=sr(()=>this.extension.client?{...this.previous?.getAllClientExtensions(),...this.extension.client}:this.previous?.getAllClientExtensions());batchCallbacks=sr(()=>{let t=this.previous?.getAllBatchQueryCallbacks()??[],r=this.extension.query?.$__internalBatch;return r?t.concat(r):t});getAllComputedFields(t){return this.computedFieldsCache.getOrCreate(t,()=>ha(this.previous?.getAllComputedFields(t),this.extension,t))}getAllClientExtensions(){return this.clientExtensions.get()}getAllModelExtensions(t){return this.modelExtensionsCache.getOrCreate(t,()=>{let r=ve(t);return!this.extension.model||!(this.extension.model[r]||this.extension.model.$allModels)?this.previous?.getAllModelExtensions(t):{...this.previous?.getAllModelExtensions(t),...this.extension.model.$allModels,...this.extension.model[r]}})}getAllQueryCallbacks(t,r){return this.queryCallbacksCache.getOrCreate(`${t}:${r}`,()=>{let n=this.previous?.getAllQueryCallbacks(t,r)??[],i=[],o=this.extension.query;return!o||!(o[t]||o.$allModels||o[r]||o.$allOperations)?n:(o[t]!==void 0&&(o[t][r]!==void 0&&i.push(o[t][r]),o[t].$allOperations!==void 0&&i.push(o[t].$allOperations)),t!==\"$none\"&&o.$allModels!==void 0&&(o.$allModels[r]!==void 0&&i.push(o.$allModels[r]),o.$allModels.$allOperations!==void 0&&i.push(o.$allModels.$allOperations)),o[r]!==void 0&&i.push(o[r]),o.$allOperations!==void 0&&i.push(o.$allOperations),n.concat(i))})}getAllBatchQueryCallbacks(){return this.batchCallbacks.get()}},Ct=class e{constructor(t){this.head=t}static empty(){return new e}static single(t){return new e(new kn(t))}isEmpty(){return this.head===void 0}append(t){return new e(new kn(t,this.head))}getAllComputedFields(t){return this.head?.getAllComputedFields(t)}getAllClientExtensions(){return this.head?.getAllClientExtensions()}getAllModelExtensions(t){return this.head?.getAllModelExtensions(t)}getAllQueryCallbacks(t,r){return this.head?.getAllQueryCallbacks(t,r)??[]}getAllBatchQueryCallbacks(){return this.head?.getAllBatchQueryCallbacks()??[]}};var On=class{constructor(t){this.name=t}};function xa(e){return e instanceof On}function ba(e){return new On(e)}var Pa=Symbol(),yr=class{constructor(t){if(t!==Pa)throw new Error(\"Skip instance can not be constructed directly\")}ifUndefined(t){return t===void 0?Dn:t}},Dn=new yr(Pa);function Te(e){return e instanceof yr}var am={findUnique:\"findUnique\",findUniqueOrThrow:\"findUniqueOrThrow\",findFirst:\"findFirst\",findFirstOrThrow:\"findFirstOrThrow\",findMany:\"findMany\",count:\"aggregate\",create:\"createOne\",createMany:\"createMany\",createManyAndReturn:\"createManyAndReturn\",update:\"updateOne\",updateMany:\"updateMany\",updateManyAndReturn:\"updateManyAndReturn\",upsert:\"upsertOne\",delete:\"deleteOne\",deleteMany:\"deleteMany\",executeRaw:\"executeRaw\",queryRaw:\"queryRaw\",aggregate:\"aggregate\",groupBy:\"groupBy\",runCommandRaw:\"runCommandRaw\",findRaw:\"findRaw\",aggregateRaw:\"aggregateRaw\"},va=\"explicitly `undefined` values are not allowed\";function Nn({modelName:e,action:t,args:r,runtimeDataModel:n,extensions:i=Ct.empty(),callsite:o,clientMethod:s,errorFormat:a,clientVersion:l,previewFeatures:c,globalOmit:u}){let p=new Bi({runtimeDataModel:n,modelName:e,action:t,rootArgs:r,callsite:o,extensions:i,selectionPath:[],argumentPath:[],originalMethod:s,errorFormat:a,clientVersion:l,previewFeatures:c,globalOmit:u});return{modelName:e,action:am[t],query:hr(r,p)}}function hr({select:e,include:t,...r}={},n){let i=r.omit;return delete r.omit,{arguments:Aa(r,n),selection:lm(e,t,i,n)}}function lm(e,t,r,n){return e?(t?n.throwValidationError({kind:\"MutuallyExclusiveFields\",firstField:\"include\",secondField:\"select\",selectionPath:n.getSelectionPath()}):r&&n.throwValidationError({kind:\"MutuallyExclusiveFields\",firstField:\"omit\",secondField:\"select\",selectionPath:n.getSelectionPath()}),dm(e,n)):cm(n,t,r)}function cm(e,t,r){let n={};return e.modelOrType&&!e.isRawAction()&&(n.$composites=!0,n.$scalars=!0),t&&um(n,t,e),pm(n,r,e),n}function um(e,t,r){for(let[n,i]of Object.entries(t)){if(Te(i))continue;let o=r.nestSelection(n);if(Qi(i,o),i===!1||i===void 0){e[n]=!1;continue}let s=r.findField(n);if(s&&s.kind!==\"object\"&&r.throwValidationError({kind:\"IncludeOnScalar\",selectionPath:r.getSelectionPath().concat(n),outputType:r.getOutputTypeDescription()}),s){e[n]=hr(i===!0?{}:i,o);continue}if(i===!0){e[n]=!0;continue}e[n]=hr(i,o)}}function pm(e,t,r){let n=r.getComputedFields(),i={...r.getGlobalOmit(),...t},o=Ea(i,n);for(let[s,a]of Object.entries(o)){if(Te(a))continue;Qi(a,r.nestSelection(s));let l=r.findField(s);n?.[s]&&!l||(e[s]=!a)}}function dm(e,t){let r={},n=t.getComputedFields(),i=wa(e,n);for(let[o,s]of Object.entries(i)){if(Te(s))continue;let a=t.nestSelection(o);Qi(s,a);let l=t.findField(o);if(!(n?.[o]&&!l)){if(s===!1||s===void 0||Te(s)){r[o]=!1;continue}if(s===!0){l?.kind===\"object\"?r[o]=hr({},a):r[o]=!0;continue}r[o]=hr(s,a)}}return r}function Ta(e,t){if(e===null)return null;if(typeof e==\"string\"||typeof e==\"number\"||typeof e==\"boolean\")return e;if(typeof e==\"bigint\")return{$type:\"BigInt\",value:String(e)};if(ft(e)){if(ln(e))return{$type:\"DateTime\",value:e.toISOString()};t.throwValidationError({kind:\"InvalidArgumentValue\",selectionPath:t.getSelectionPath(),argumentPath:t.getArgumentPath(),argument:{name:t.getArgumentName(),typeNames:[\"Date\"]},underlyingError:\"Provided Date object is invalid\"})}if(xa(e))return{$type:\"Param\",value:e.name};if(Tt(e))return{$type:\"FieldRef\",value:{_ref:e.name,_container:e.modelName}};if(Array.isArray(e))return mm(e,t);if(ArrayBuffer.isView(e)){let{buffer:r,byteOffset:n,byteLength:i}=e;return{$type:\"Bytes\",value:Buffer.from(r,n,i).toString(\"base64\")}}if(fm(e))return e.values;if(ht(e))return{$type:\"Decimal\",value:e.toFixed()};if(e instanceof Ne){if(e!==Cn.instances[e._getName()])throw new Error(\"Invalid ObjectEnumValue\");return{$type:\"Enum\",value:e._getName()}}if(gm(e))return e.toJSON();if(typeof e==\"object\")return Aa(e,t);t.throwValidationError({kind:\"InvalidArgumentValue\",selectionPath:t.getSelectionPath(),argumentPath:t.getArgumentPath(),argument:{name:t.getArgumentName(),typeNames:[]},underlyingError:`We could not serialize ${Object.prototype.toString.call(e)} value. Serialize the object to JSON or implement a \".toJSON()\" method on it`})}function Aa(e,t){if(e.$type)return{$type:\"Raw\",value:e};let r={};for(let n in e){let i=e[n],o=t.nestArgument(n);Te(i)||(i!==void 0?r[n]=Ta(i,o):t.isPreviewFeatureOn(\"strictUndefinedChecks\")&&t.throwValidationError({kind:\"InvalidArgumentValue\",argumentPath:o.getArgumentPath(),selectionPath:t.getSelectionPath(),argument:{name:t.getArgumentName(),typeNames:[]},underlyingError:va}))}return r}function mm(e,t){let r=[];for(let n=0;n<e.length;n++){let i=t.nestArgument(String(n)),o=e[n];if(o===void 0||Te(o)){let s=o===void 0?\"undefined\":\"Prisma.skip\";t.throwValidationError({kind:\"InvalidArgumentValue\",selectionPath:i.getSelectionPath(),argumentPath:i.getArgumentPath(),argument:{name:`${t.getArgumentName()}[${n}]`,typeNames:[]},underlyingError:`Can not use \\`${s}\\` value within array. Use \\`null\\` or filter out \\`${s}\\` values`})}r.push(Ta(o,i))}return r}function fm(e){return typeof e==\"object\"&&e!==null&&e.__prismaRawParameters__===!0}function gm(e){return typeof e==\"object\"&&e!==null&&typeof e.toJSON==\"function\"}function Qi(e,t){e===void 0&&t.isPreviewFeatureOn(\"strictUndefinedChecks\")&&t.throwValidationError({kind:\"InvalidSelectionValue\",selectionPath:t.getSelectionPath(),underlyingError:va})}var Bi=class e{constructor(t){this.params=t;this.params.modelName&&(this.modelOrType=this.params.runtimeDataModel.models[this.params.modelName]??this.params.runtimeDataModel.types[this.params.modelName])}modelOrType;throwValidationError(t){In({errors:[t],originalMethod:this.params.originalMethod,args:this.params.rootArgs??{},callsite:this.params.callsite,errorFormat:this.params.errorFormat,clientVersion:this.params.clientVersion,globalOmit:this.params.globalOmit})}getSelectionPath(){return this.params.selectionPath}getArgumentPath(){return this.params.argumentPath}getArgumentName(){return this.params.argumentPath[this.params.argumentPath.length-1]}getOutputTypeDescription(){if(!(!this.params.modelName||!this.modelOrType))return{name:this.params.modelName,fields:this.modelOrType.fields.map(t=>({name:t.name,typeName:\"boolean\",isRelation:t.kind===\"object\"}))}}isRawAction(){return[\"executeRaw\",\"queryRaw\",\"runCommandRaw\",\"findRaw\",\"aggregateRaw\"].includes(this.params.action)}isPreviewFeatureOn(t){return this.params.previewFeatures.includes(t)}getComputedFields(){if(this.params.modelName)return this.params.extensions.getAllComputedFields(this.params.modelName)}findField(t){return this.modelOrType?.fields.find(r=>r.name===t)}nestSelection(t){let r=this.findField(t),n=r?.kind===\"object\"?r.type:void 0;return new e({...this.params,modelName:n,selectionPath:this.params.selectionPath.concat(t)})}getGlobalOmit(){return this.params.modelName&&this.shouldApplyGlobalOmit()?this.params.globalOmit?.[Le(this.params.modelName)]??{}:{}}shouldApplyGlobalOmit(){switch(this.params.action){case\"findFirst\":case\"findFirstOrThrow\":case\"findUniqueOrThrow\":case\"findMany\":case\"upsert\":case\"findUnique\":case\"createManyAndReturn\":case\"create\":case\"update\":case\"updateManyAndReturn\":case\"delete\":return!0;case\"executeRaw\":case\"aggregateRaw\":case\"runCommandRaw\":case\"findRaw\":case\"createMany\":case\"deleteMany\":case\"groupBy\":case\"updateMany\":case\"count\":case\"aggregate\":case\"queryRaw\":return!1;default:Ie(this.params.action,\"Unknown action\")}}nestArgument(t){return new e({...this.params,argumentPath:this.params.argumentPath.concat(t)})}};function Ca(e){if(!e._hasPreviewFlag(\"metrics\"))throw new X(\"`metrics` preview feature must be enabled in order to access metrics API\",{clientVersion:e._clientVersion})}var Rt=class{_client;constructor(t){this._client=t}prometheus(t){return Ca(this._client),this._client._engine.metrics({format:\"prometheus\",...t})}json(t){return Ca(this._client),this._client._engine.metrics({format:\"json\",...t})}};function Ra(e,t){let r=sr(()=>ym(t));Object.defineProperty(e,\"dmmf\",{get:()=>r.get()})}function ym(e){return{datamodel:{models:Hi(e.models),enums:Hi(e.enums),types:Hi(e.types)}}}function Hi(e){return Object.entries(e).map(([t,r])=>({name:t,...r}))}var Gi=new WeakMap,_n=\"$$PrismaTypedSql\",wr=class{constructor(t,r){Gi.set(this,{sql:t,values:r}),Object.defineProperty(this,_n,{value:_n})}get sql(){return Gi.get(this).sql}get values(){return Gi.get(this).values}};function Sa(e){return(...t)=>new wr(e,t)}function Mn(e){return e!=null&&e[_n]===_n}var Pu=H(xi());var vu=require(\"node:async_hooks\"),Tu=require(\"node:events\"),Au=H(require(\"node:fs\")),mi=H(require(\"node:path\"));var ce=class e{constructor(t,r){if(t.length-1!==r.length)throw t.length===0?new TypeError(\"Expected at least 1 string\"):new TypeError(`Expected ${t.length} strings to have ${t.length-1} values`);let n=r.reduce((s,a)=>s+(a instanceof e?a.values.length:1),0);this.values=new Array(n),this.strings=new Array(n+1),this.strings[0]=t[0];let i=0,o=0;for(;i<r.length;){let s=r[i++],a=t[i];if(s instanceof e){this.strings[o]+=s.strings[0];let l=0;for(;l<s.values.length;)this.values[o++]=s.values[l++],this.strings[o]=s.strings[l];this.strings[o]+=a}else this.values[o++]=s,this.strings[o]=a}}get sql(){let t=this.strings.length,r=1,n=this.strings[0];for(;r<t;)n+=`?${this.strings[r++]}`;return n}get statement(){let t=this.strings.length,r=1,n=this.strings[0];for(;r<t;)n+=`:${r}${this.strings[r++]}`;return n}get text(){let t=this.strings.length,r=1,n=this.strings[0];for(;r<t;)n+=`$${r}${this.strings[r++]}`;return n}inspect(){return{sql:this.sql,statement:this.statement,text:this.text,values:this.values}}};function Ia(e,t=\",\",r=\"\",n=\"\"){if(e.length===0)throw new TypeError(\"Expected `join([])` to be called with an array of multiple elements, but got an empty array\");return new ce([r,...Array(e.length-1).fill(t),n],e)}function Ji(e){return new ce([e],[])}var ka=Ji(\"\");function Wi(e,...t){return new ce(e,t)}function Er(e){return{getKeys(){return Object.keys(e)},getPropertyValue(t){return e[t]}}}function ie(e,t){return{getKeys(){return[e]},getPropertyValue(){return t()}}}function Ze(e){let t=new Ee;return{getKeys(){return e.getKeys()},getPropertyValue(r){return t.getOrCreate(r,()=>e.getPropertyValue(r))},getPropertyDescriptor(r){return e.getPropertyDescriptor?.(r)}}}var Fn={enumerable:!0,configurable:!0,writable:!0};function Ln(e){let t=new Set(e);return{getPrototypeOf:()=>Object.prototype,getOwnPropertyDescriptor:()=>Fn,has:(r,n)=>t.has(n),set:(r,n,i)=>t.add(n)&&Reflect.set(r,n,i),ownKeys:()=>[...t]}}var Oa=Symbol.for(\"nodejs.util.inspect.custom\");function he(e,t){let r=hm(t),n=new Set,i=new Proxy(e,{get(o,s){if(n.has(s))return o[s];let a=r.get(s);return a?a.getPropertyValue(s):o[s]},has(o,s){if(n.has(s))return!0;let a=r.get(s);return a?a.has?.(s)??!0:Reflect.has(o,s)},ownKeys(o){let s=Da(Reflect.ownKeys(o),r),a=Da(Array.from(r.keys()),r);return[...new Set([...s,...a,...n])]},set(o,s,a){return r.get(s)?.getPropertyDescriptor?.(s)?.writable===!1?!1:(n.add(s),Reflect.set(o,s,a))},getOwnPropertyDescriptor(o,s){let a=Reflect.getOwnPropertyDescriptor(o,s);if(a&&!a.configurable)return a;let l=r.get(s);return l?l.getPropertyDescriptor?{...Fn,...l?.getPropertyDescriptor(s)}:Fn:a},defineProperty(o,s,a){return n.add(s),Reflect.defineProperty(o,s,a)},getPrototypeOf:()=>Object.prototype});return i[Oa]=function(){let o={...this};return delete o[Oa],o},i}function hm(e){let t=new Map;for(let r of e){let n=r.getKeys();for(let i of n)t.set(i,r)}return t}function Da(e,t){return e.filter(r=>t.get(r)?.has?.(r)??!0)}function St(e){return{getKeys(){return e},has(){return!1},getPropertyValue(){}}}function It(e,t){return{batch:e,transaction:t?.kind===\"batch\"?{isolationLevel:t.options.isolationLevel}:void 0}}function Na(e){if(e===void 0)return\"\";let t=At(e);return new Et(0,{colors:vn}).write(t).toString()}var wm=\"P2037\";function $n({error:e,user_facing_error:t},r,n){return t.error_code?new U(Em(t,n),{code:t.error_code,clientVersion:r,meta:t.meta,batchRequestIdx:t.batch_request_idx}):new J(e,{clientVersion:r,batchRequestIdx:t.batch_request_idx})}function Em(e,t){let r=e.message;return(t===\"postgresql\"||t===\"postgres\"||t===\"mysql\")&&e.error_code===wm&&(r+=`\n  25 Prisma Accelerate has built-in connection pooling to prevent such errors: https://pris.ly/client/error-accelerate`),r}var xr=\"<unknown>\";function _a(e){var t=e.split(`\n→ 26 `);return t.reduce(function(r,n){var i=Pm(n)||Tm(n)||Rm(n)||Om(n)||Im(n);return i&&r.push(i),r},[])}var xm=/^\\s*at (.*?) ?\\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\\/|[a-z]:\\\\|\\\\\\\\).*?)(?::(\\d+))?(?::(\\d+))?\\)?\\s*$/i,bm=/\\((\\S*)(?::(\\d+))(?::(\\d+))\\)/;function Pm(e){var t=xm.exec(e);if(!t)return null;var r=t[2]&&t[2].indexOf(\"native\")===0,n=t[2]&&t[2].indexOf(\"eval\")===0,i=bm.exec(t[2]);return n&&i!=null&&(t[2]=i[1],t[3]=i[2],t[4]=i[3]),{file:r?null:t[2],methodName:t[1]||xr,arguments:r?[t[2]]:[],lineNumber:t[3]?+t[3]:null,column:t[4]?+t[4]:null}}var vm=/^\\s*at (?:((?:\\[object object\\])?.+) )?\\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\\d+)(?::(\\d+))?\\)?\\s*$/i;function Tm(e){var t=vm.exec(e);return t?{file:t[2],methodName:t[1]||xr,arguments:[],lineNumber:+t[3],column:t[4]?+t[4]:null}:null}var Am=/^\\s*(.*?)(?:\\((.*?)\\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\\[native).*?|[^@]*bundle)(?::(\\d+))?(?::(\\d+))?\\s*$/i,Cm=/(\\S+) line (\\d+)(?: > eval line \\d+)* > eval/i;function Rm(e){var t=Am.exec(e);if(!t)return null;var r=t[3]&&t[3].indexOf(\" > eval\")>-1,n=Cm.exec(t[3]);return r&&n!=null&&(t[3]=n[1],t[4]=n[2],t[5]=null),{file:t[3],methodName:t[1]||xr,arguments:t[2]?t[2].split(\",\"):[],lineNumber:t[4]?+t[4]:null,column:t[5]?+t[5]:null}}var Sm=/^\\s*(?:([^@]*)(?:\\((.*?)\\))?@)?(\\S.*?):(\\d+)(?::(\\d+))?\\s*$/i;function Im(e){var t=Sm.exec(e);return t?{file:t[3],methodName:t[1]||xr,arguments:[],lineNumber:+t[4],column:t[5]?+t[5]:null}:null}var km=/^\\s*at (?:((?:\\[object object\\])?[^\\\\/]+(?: \\[as \\S+\\])?) )?\\(?(.*?):(\\d+)(?::(\\d+))?\\)?\\s*$/i;function Om(e){var t=km.exec(e);return t?{file:t[2],methodName:t[1]||xr,arguments:[],lineNumber:+t[3],column:t[4]?+t[4]:null}:null}var Ki=class{getLocation(){return null}},zi=class{_error;constructor(){this._error=new Error}getLocation(){let t=this._error.stack;if(!t)return null;let n=_a(t).find(i=>{if(!i.file)return!1;let o=Ai(i.file);return o!==\"<anonymous>\"&&!o.includes(\"@prisma\")&&!o.includes(\"/packages/client/src/runtime/\")&&!o.endsWith(\"/runtime/binary.js\")&&!o.endsWith(\"/runtime/library.js\")&&!o.endsWith(\"/runtime/edge.js\")&&!o.endsWith(\"/runtime/edge-esm.js\")&&!o.startsWith(\"internal/\")&&!i.methodName.includes(\"new \")&&!i.methodName.includes(\"getCallSite\")&&!i.methodName.includes(\"Proxy.\")&&i.methodName.split(\".\").length<4});return!n||!n.file?null:{fileName:n.file,lineNumber:n.lineNumber,columnNumber:n.column}}};function Be(e){return e===\"minimal\"?typeof $EnabledCallSite==\"function\"&&e!==\"minimal\"?new $EnabledCallSite:new Ki:new zi}var Ma={_avg:!0,_count:!0,_sum:!0,_min:!0,_max:!0};function kt(e={}){let t=Nm(e);return Object.entries(t).reduce((n,[i,o])=>(Ma[i]!==void 0?n.select[i]={select:o}:n[i]=o,n),{select:{}})}function Nm(e={}){return typeof e._count==\"boolean\"?{...e,_count:{_all:e._count}}:e}function Vn(e={}){return t=>(typeof e._count==\"boolean\"&&(t._count=t._count._all),t)}function Fa(e,t){let r=Vn(e);return t({action:\"aggregate\",unpacker:r,argsMapper:kt})(e)}function _m(e={}){let{select:t,...r}=e;return typeof t==\"object\"?kt({...r,_count:t}):kt({...r,_count:{_all:!0}})}function Mm(e={}){return typeof e.select==\"object\"?t=>Vn(e)(t)._count:t=>Vn(e)(t)._count._all}function La(e,t){return t({action:\"count\",unpacker:Mm(e),argsMapper:_m})(e)}function Fm(e={}){let t=kt(e);if(Array.isArray(t.by))for(let r of t.by)typeof r==\"string\"&&(t.select[r]=!0);else typeof t.by==\"string\"&&(t.select[t.by]=!0);return t}function Lm(e={}){return t=>(typeof e?._count==\"boolean\"&&t.forEach(r=>{r._count=r._count._all}),t)}function $a(e,t){return t({action:\"groupBy\",unpacker:Lm(e),argsMapper:Fm})(e)}function Va(e,t,r){if(t===\"aggregate\")return n=>Fa(n,r);if(t===\"count\")return n=>La(n,r);if(t===\"groupBy\")return n=>$a(n,r)}function qa(e,t){let r=t.fields.filter(i=>!i.relationName),n=Ds(r,\"name\");return new Proxy({},{get(i,o){if(o in i||typeof o==\"symbol\")return i[o];let s=n[o];if(s)return new pr(e,o,s.type,s.isList,s.kind===\"enum\")},...Ln(Object.keys(n))})}var Ua=e=>Array.isArray(e)?e:e.split(\".\"),Yi=(e,t)=>Ua(t).reduce((r,n)=>r&&r[n],e),ja=(e,t,r)=>Ua(t).reduceRight((n,i,o,s)=>Object.assign({},Yi(e,s.slice(0,o)),{[i]:n}),r);function $m(e,t){return e===void 0||t===void 0?[]:[...t,\"select\",e]}function Vm(e,t,r){return t===void 0?e??{}:ja(t,r,e||!0)}function Zi(e,t,r,n,i,o){let a=e._runtimeDataModel.models[t].fields.reduce((l,c)=>({...l,[c.name]:c}),{});return l=>{let c=Be(e._errorFormat),u=$m(n,i),p=Vm(l,o,u),d=r({dataPath:u,callsite:c})(p),m=qm(e,t);return new Proxy(d,{get(y,g){if(!m.includes(g))return y[g];let A=[a[g].type,r,g],C=[u,p];return Zi(e,...A,...C)},...Ln([...m,...Object.getOwnPropertyNames(d)])})}}function qm(e,t){return e._runtimeDataModel.models[t].fields.filter(r=>r.kind===\"object\").map(r=>r.name)}var Um=[\"findUnique\",\"findUniqueOrThrow\",\"findFirst\",\"findFirstOrThrow\",\"create\",\"update\",\"upsert\",\"delete\"],jm=[\"aggregate\",\"count\",\"groupBy\"];function Xi(e,t){let r=e._extensions.getAllModelExtensions(t)??{},n=[Bm(e,t),Hm(e,t),Er(r),ie(\"name\",()=>t),ie(\"$name\",()=>t),ie(\"$parent\",()=>e._appliedParent)];return he({},n)}function Bm(e,t){let r=ve(t),n=Object.keys(wt).concat(\"count\");return{getKeys(){return n},getPropertyValue(i){let o=i,s=a=>l=>{let c=Be(e._errorFormat);return e._createPrismaPromise(u=>{let p={args:l,dataPath:[],action:o,model:t,clientMethod:`${r}.${i}`,jsModelName:r,transaction:u,callsite:c};return e._request({...p,...a})},{action:o,args:l,model:t})};return Um.includes(o)?Zi(e,t,s):Qm(i)?Va(e,i,s):s({})}}}function Qm(e){return jm.includes(e)}function Hm(e,t){return Ze(ie(\"fields\",()=>{let r=e._runtimeDataModel.models[t];return qa(t,r)}))}function Ba(e){return e.replace(/^./,t=>t.toUpperCase())}var eo=Symbol();function br(e){let t=[Gm(e),Jm(e),ie(eo,()=>e),ie(\"$parent\",()=>e._appliedParent)],r=e._extensions.getAllClientExtensions();return r&&t.push(Er(r)),he(e,t)}function Gm(e){let t=Object.getPrototypeOf(e._originalClient),r=[...new Set(Object.getOwnPropertyNames(t))];return{getKeys(){return r},getPropertyValue(n){return e[n]}}}function Jm(e){let t=Object.keys(e._runtimeDataModel.models),r=t.map(ve),n=[...new Set(t.concat(r))];return Ze({getKeys(){return n},getPropertyValue(i){let o=Ba(i);if(e._runtimeDataModel.models[o]!==void 0)return Xi(e,o);if(e._runtimeDataModel.models[i]!==void 0)return Xi(e,i)},getPropertyDescriptor(i){if(!r.includes(i))return{enumerable:!1}}})}function Qa(e){return e[eo]?e[eo]:e}function Ha(e){if(typeof e==\"function\")return e(this);if(e.client?.__AccelerateEngine){let r=e.client.__AccelerateEngine;this._originalClient._engine=new r(this._originalClient._accelerateEngineConfig)}let t=Object.create(\nUnique constraint failed on the fields: (`\"resourceId\"`, `\"resourceType\"`, `\"requestedByUserId\"`)"

Severity

🔹 Minor: Unexpected behavior, but does not block development

Reproduction

  • using the new prisma rust-free query + [email protected]
  • generate any DB err, like UniqueConstraintViolation
  • no target property under the meta property of a PrismaClientKnownRequestError

Expected vs. Actual Behavior

Image

Frequency

Consistently reproducible

Does this occur in development or production?

Only in production (e.g., query engine, generated client)

Is this a regression?

No

Workaround

No

Prisma Schema & Queries

No

Prisma Config

No response

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

// Prisma version output
prisma                : 6.17.1
@prisma/client        : 6.17.1
Computed binaryTarget : darwin-arm64
Operating System      : darwin
Architecture          : arm64
Node.js               : v22.14.0
TypeScript            : 5.5.4
Query Compiler        : enabled
PSL                   : @prisma/prisma-schema-wasm 6.17.1-1.272a37d34178c2894197e17273bf937f25acdeac
Schema Engine         : schema-engine-cli 272a37d34178c2894197e17273bf937f25acdeac (at ../../node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash  : 272a37d34178c2894197e17273bf937f25acdeac
Studio                : 0.511.0
Preview Features      : relationJoins, typedSql

Activity

  1. added
    kind/bug
    on Oct 12, 2025
  2. jacek-prisma commented on Oct 14, 2025

    @jacek-prisma
    Contributor

    Hi @0xb4lamx
    This field is not public API, we might bring something in its place but you shouldn't rely on the shape of the meta object right now.

    As for your specific issue, there seems to be an error during the creation of the error, which is not normal. If you provide reproduction steps (schema + code snippet) we could look into it.

  3. added
    bug/0-unknown
    on Oct 14, 2025
  4. 0xb4lamx commented on Oct 14, 2025

    @0xb4lamx
    Author

    Hey @jacek-prisma, thanks for taking a look into this.

    Hi @0xb4lamx This field is not public API, we might bring something in its place but you shouldn't rely on the shape of the meta object right now.

    why target property is not there anymore? it is needed to filter constraints errors!

    As for your specific issue, there seems to be an error during the creation of the error, which is not normal. If you provide reproduction steps (schema + code snippet) we could look into it.

    I’ve already shared reproduction steps — for example, in any schema, add a unique constraint and then try inserting a duplicate record. This will trigger a UniqueConstraintViolation with the mentioned error message.

  5. jacek-prisma commented on Oct 14, 2025

    @jacek-prisma
    Contributor

    Hi @0xb4lamx
    I'm referring to

    Invalid t=Object.create() invocation in .../.prisma/client/runtime/client.js:26:2556

    that looks like something that does not normally appear in our error message, it'd be useful have a reproduction for that

  6. aqrln commented on Oct 20, 2025

    @aqrln
    Member

    why target property is not there anymore?

    Short answer is because all properties in meta are driver specific, and you're now using a different driver.

    it is needed to filter constraints errors!

    I believe this information is available on your screenshot in meta.driverAdapterError.cause.constraint.fields.

  7. 0xb4lamx commented on Oct 20, 2025

    @0xb4lamx
    Author

    I believe this information is available on your screenshot in meta.driverAdapterError.cause.constraint.fields.

    @aqrln thanks for that! then why https://github.com/prisma/prisma/blob/423b58507879080bdc1273ca5d30b3de87e5b766/packages/driver-adapter-utils/src/error.ts are not exported through importable packages?

    • it will be needed for proper typing
      or what do you recommend for type checking in this case?
  8. macrozone commented on Dec 23, 2025

    @macrozone

    meta.target is officially mentioned in the docs, so i'd consider it public api, but I understand such semi-internals are hard to keep in semver properly.

    It would be cool though to have an official prop on the error that indicates which field(s) triggered the error. meta.driverAdapterError.cause.constraint.fields looks even less stable then the old meta.target

  9. AfikH commented on Jan 30, 2026

    @AfikH

    How are we expected to use the package without being able to let the client know which unique constraint failed during its request?

    • Is there any official solution for this basic feature?
    • I'd love you know if any of you guys found a solution that you're happy with.
  10. rafma0 commented on Feb 6, 2026

    @rafma0
    case err instanceof PrismaClientKnownRequestError:
      switch (err.code) {
        // Unique constraint failed on the {constraint}
        case 'P2002': {
          // https://github.com/prisma/prisma/issues/28281
          const fields = (err as any)?.meta?.driverAdapterError?.cause?.constraint?.fields
          const message = Array.isArray(fields)
            ? fields.map((f: string) => f.replace(/"/g, '')).join(', ')
            : 'unique constraint violation'
          res.status(409).json({ message })
          break
        }

    I regret nothing.

  11. darcqstar commented on Feb 19, 2026

    @darcqstar

    This field is not public API, we might bring something in its place but you shouldn't rely on the shape of the meta object right now.

    If we are not supposed to depend on the meta object shouldn't this be removed from the docs? Otherwise it's misleading. https://www.prisma.io/docs/orm/reference/error-reference#prismaclientknownrequesterror

    I feel like knowing which field is violating the unique constraint is such an important thing to know. For example, in a table where username and email are both unique, we should let the user know which field exactly is taken and not.

    Given the fact that error.message already has the field name in some form: Unique constraint failed on the fields: (username), is it not possible to get that value in a clean way?

    While the solution mentioned in the above comment may work, I feel like it's a very hacky way to get an important value like this. Plus, as it's mentioned above, if we are not meant to depend on the meta object, I don't think digging very deep inside it in that fashion is a good idea either.

    I think this is only an issue when there are more than 1 unique fields in the table. If there is only one we would know which field it is.

    So yeah, I think it would be great if we can have an API that gives us the exact field name that violates the constraint.

  12. shemaikuzwe commented on Mar 4, 2026

    @shemaikuzwe

    I think this issues if not fixed should be added in docs because it is misleading people so much.

  13. sommeeeer commented on Mar 25, 2026

    @sommeeeer

    I would also like to see which field that the constraint failed on

  14. matthewnanas commented on Mar 25, 2026

    @matthewnanas

    I think this issues if not fixed should be added in docs because it is misleading people so much.

    Please 🙏 lol, this was a bit of a rabbithole, and I'm casting meta.driverAdapterError to { cause?: { constraint?: { fields?: string[] } } } which is not ideal...

  15. sommeeeer commented on Mar 26, 2026

    @sommeeeer

    I would love to find a workaround for this. meta.driverAdapterError is not working for me. I can't access the cause property

  16. timhaines commented on Apr 21, 2026

    @timhaines

    Following up on this thread with a case where the meta.target change stops being a shape change and becomes a correctness issue: partial unique indexes.

    Our schema has two unique constraints on app.account_memberships whose key sets overlap:

    • a full unique on (user_id, account_id) — "a user is a member of an account at most once"
    • a partial unique on (account_id) WHERE role = 'owner', named account_memberships_one_owner_per_account — "at most one owner per account"

    With the Rust query engine, a second role='owner' insert surfaced as P2002 with meta.target = ['account_memberships_one_owner_per_account'] — the index name was the only field that distinguished it from the full-unique violation. With @prisma/[email protected] both now surface as { kind: "UniqueConstraintViolation", constraint: { fields: ['account_id'] } } (or similar column lists). The index name is only accessible via meta.driverAdapterError.cause.originalMessage, which per maintainer responses earlier in this thread is explicitly not public API.

    Root cause is in adapter-pg's mapDriverError: the "23505" branch discards error.constraint (populated by node-postgres from PG_DIAG_CONSTRAINT_NAME) and regex-extracts column names from error.detail instead, whereas the "23503" branch in the same function does use error.constraint via { index: error.constraint }. The MySQL adapter preserves the index name on 1062 per #29344, so Postgres is the outlier. I've opened #29495 with the adapter-level specifics and a suggested fix.

    The broader request here is: whatever ends up replacing meta.driverAdapterError needs to carry the constraint name, not only the column list, for partial indexes to be distinguishable.

  17. nils44344 commented on Oct 20, 2026

    @nils44344

    A data point on 7.10.1 for anyone writing a handler today. With driver adapters, e.meta.target was undefined on both Postgres (@prisma/adapter-pg) and SQLite (@prisma/adapter-better-sqlite3). The constraint is under meta.driverAdapterError.cause.constraint, but its shape depends on the adapter:

    • Postgres: { "index": "User_email_key" }, and the message says Unique constraint failed on the constraint: `User_email_key`
    • SQLite: { "fields": ["email"] }, and the message still says on the fields: (`email`)

    Prisma 6.19.3 without an adapter still gives meta.target: ["email"].

    This returned User_email_key on Postgres and email on SQLite, and falls back to meta.target otherwise:

    const which = (e: any) => {
      const c = e?.meta?.driverAdapterError?.cause?.constraint;
      return c?.fields?.join(',') ?? c?.index ?? e?.meta?.target;
    };

    Repro: https://github.com/nils44344/nk-repro/tree/main/p2002
    Write-up: https://nilaykabariya.blog/database/prisma-p2002-unique-constraint-failed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/0-unknownkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions