{"record":{"id":"f1f78d91a43d44d0","repo":"ent/ent","slug":"pkg-check-existence-w","errorCode":null,"errorMessage":"{{ $pkg }}: check existence: %w","messagePattern":"(.+?)\\}: check existence: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"entc/gen/template/builder/query.tmpl","lineNumber":276,"sourceCode":"}\n\n// CountX is like Count, but panics if an error occurs.\nfunc ({{ $receiver }} *{{ $builder }}) CountX(ctx context.Context) int {\n\tcount, err := {{ $receiver }}.Count(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn count\n}\n\n// Exist returns true if the query has elements in the graph.\nfunc ({{ $receiver }} *{{ $builder }}) Exist(ctx context.Context) (bool, error) {\n\tctx = setContextOp(ctx, {{ $receiver }}.ctx, ent.OpQueryExist)\n\tswitch _, err := {{ $receiver }}.First{{ if $.HasOneFieldID }}ID{{ end }}(ctx);{\n\tcase IsNotFound(err):\n\t\treturn false, nil\n\tcase err != nil:\n\t\treturn false, fmt.Errorf(\"{{ $pkg }}: check existence: %w\", err)\n\tdefault:\n\t\treturn true, nil\n\t}\n}\n\n// ExistX is like Exist, but panics if an error occurs.\nfunc ({{ $receiver }} *{{ $builder }}) ExistX(ctx context.Context) bool {\n\texist, err := {{ $receiver }}.Exist(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn exist\n}\n\n// Clone returns a duplicate of the {{ $builder }} builder, including all associated steps. It can be\n// used to prepare common query builders and use them differently after the clone is made.\nfunc ({{ $receiver }} *{{ $builder }}) Clone() *{{ $builder }} {\n\tif {{ $receiver }} == nil {","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/entc/gen/template/builder/query.tmpl#L258-L294","documentation":"The generated query builder's Exist(ctx) method runs FirstID (or First) and maps the result: not-found means false, any other error is wrapped as \"<pkg>: check existence: %w\". The error itself just signals that the existence check could not complete — the real cause is in the wrapped error (connection failure, syntax error, driver issue, etc.).","triggerScenarios":"Calling client.User.Query().Where(...).Exist(ctx) and the underlying FirstID/First query fails for any reason other than entc.NotFound — e.g. DB is down, invalid predicate produces bad SQL, context canceled.","commonSituations":"Database connection dropped mid-request; misconfigured predicates causing driver errors; context deadline exceeded on slow queries; migrations missing so a queried column/table doesn't exist.","solutions":["Unwrap the returned error to see the root cause (errors.Unwrap / %w chain).","Check database connectivity and that the table/schema exists (run migrations).","Inspect the query's predicates for invalid values or types.","Add timeouts/retry for transient connection errors."],"exampleFix":"// before\nexists, err := q.Exist(ctx)\n// after\nexists, err := q.Exist(ctx)\nif err != nil {\n    if ent.IsNotFound(err) { /* not possible for Exist, but unwrap anyway */ }\n    log.Printf(\"existence check failed: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"exists, err := q.Exist(ctx)\nif err != nil {\n    // err is wrapped cause; inspect root\n    if ctx.Err() != nil { return ctx.Err() }\n    return fmt.Errorf(\"existence check: %w\", err)\n}\nif exists { /* ... */ }","preventionTips":["Check DB health/connectivity before batch existence checks","Ensure migrations ran so queried tables/columns exist","Set sensible context timeouts"],"tags":["ent","go","database","query"],"backgroundTag":"existence-check-failed","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}