(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[156],{6411:function(s,e,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/docs/reference/client/errors",function(){return r(6776)}])},6776:function(s,e,r){"use strict";r.r(e),r.d(e,{__toc:function(){return l}});var n=r(1527),o=r(7682),i=r(6727);let l=[{depth:2,value:"ErrNotFound",id:"errnotfound"},{depth:2,value:"IsErrUniqueConstraint",id:"iserruniqueconstraint"}];function t(s){let e=Object.assign({h1:"h1",h2:"h2",p:"p",code:"code",pre:"pre",span:"span"},(0,i.a)(),s.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h1,{children:"Errors"}),"\n",(0,n.jsx)(e.h2,{id:"errnotfound",children:"ErrNotFound"}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"ErrNotFound"})," is returned when a query does not return any results. This error may be returned in ",(0,n.jsx)(e.code,{children:"FindUnique"}),", ",(0,n.jsx)(e.code,{children:"FindFirst"}),", but also when updating or deleting single records using ",(0,n.jsx)(e.code,{children:"FindUnique().Update()"})," and ",(0,n.jsx)(e.code,{children:"FindUnique().Delete()"}),"."]}),"\n",(0,n.jsx)(e.pre,{"data-language":"go","data-theme":"default",children:(0,n.jsxs)(e.code,{"data-language":"go","data-theme":"default",children:[(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"post, err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" client.Post."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"FindFirst"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  db.Post.Title."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Equals"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"hi"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"),"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:")."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Exec"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"(ctx)"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"!="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"nil"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" errors."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Is"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"(err, db.ErrNotFound) {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"panic"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:"\"no record with title 'hi' found\""}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:")"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  }"})}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"panic"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"error occurred: '}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"%s"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:", err)"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),"\n",(0,n.jsx)(e.h2,{id:"iserruniqueconstraint",children:"IsErrUniqueConstraint"}),"\n",(0,n.jsx)(e.p,{children:"A unique constraint violation happens when a query attempts to insert or update a record with a value that already exists in the database, or in other words, violates a unique constraint."}),"\n",(0,n.jsx)(e.pre,{"data-language":"go","data-theme":"default",children:(0,n.jsxs)(e.code,{"data-language":"go","data-theme":"default",children:[(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"user, err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" db.User."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"CreateOne"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"..."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:")."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Exec"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"(cxt)"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"!="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"nil"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" info, err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:":="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" db."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"IsErrUniqueConstraint"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"(err); err "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"!="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"nil"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// Fields exists for Postgres and SQLite"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    log."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Printf"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"unique constraint on the fields: '}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"%s"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:", info.Fields)"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:" "}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// you can also compare it with generated field names:"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"if"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" info.Fields["}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"0"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"] "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-keyword)"},children:"=="}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:" db.User.Name."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Field"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"() {"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"      "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// do something"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"      log."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Printf"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"unique constraint on the `user.name` field"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:")"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:" "}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-comment)"},children:"// For MySQL and MongoDB, use the constraint key"})]}),"\n",(0,n.jsxs)(e.span,{className:"line",children:[(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"    log."}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-function)"},children:"Printf"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"unique constraint on the key: '}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-constant)"},children:"%s"}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"'}),(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:", info.Key)"})]}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"  }"})}),"\n",(0,n.jsx)(e.span,{className:"line",children:(0,n.jsx)(e.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})})]})}e.default=(0,o.j)({MDXContent:function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:e}=Object.assign({},(0,i.a)(),s.components);return e?(0,n.jsx)(e,{...s,children:(0,n.jsx)(t,{...s})}):t(s)},pageOpts:{filePath:"pages/docs/reference/client/errors.md",route:"/docs/reference/client/errors",timestamp:1708501821e3,title:"Errors",headings:l},pageNextRoute:"/docs/reference/client/errors"})}},function(s){s.O(0,[682,888,774,179],function(){return s(s.s=6411)}),_N_E=s.O()}]);