{"record":{"id":"49b3078d867083b6","repo":"cayleygraph/cayley","slug":"not-found","errorCode":null,"errorMessage":"not found","messagePattern":"not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/loader.go","lineNumber":17,"sourceCode":"package schema\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"reflect\"\n\n\t\"github.com/cayleygraph/cayley/query/path\"\n\t\"github.com/cayleygraph/quad\"\n\n\t\"github.com/cayleygraph/cayley/graph\"\n\t\"github.com/cayleygraph/cayley/graph/iterator\"\n)\n\nvar (\n\terrNotFound               = errors.New(\"not found\")\n\terrRequiredFieldIsMissing = errors.New(\"required field is missing\")\n)\n\n// Optimize flags controls an optimization step performed before queries.\nvar Optimize = true\n\n// IsNotFound check if error is related to a missing object (either because of wrong ID or because of type constrains).\nfunc IsNotFound(err error) bool {\n\treturn err == errNotFound || err == errRequiredFieldIsMissing\n}\n\n// LoadTo will load a sub-graph of objects starting from ids (or from any nodes, if empty)\n// to a destination Go object. Destination can be a struct, slice or channel.\n//\n// Mapping to quads is done via Go struct tag \"quad\" or \"json\" as a fallback.\n//\n// A simplest mapping is an \"@id\" tag which saves node ID (subject of a quad) into tagged field.\n//","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/loader.go#L1-L35","documentation":"errNotFound is the schema loader's sentinel for an object that could not be loaded — either the given ID does not exist in the graph, or the entity found does not satisfy the requested type constraints. Callers should detect it with schema.IsNotFound and treat it as a 'no such entity' condition, not a hard failure.","triggerScenarios":"Calling schema.LoadTo/schema.LoadByNameTo (via loadIteratorToDepth) with a node ID absent from the store, or with a type that doesn't match the stored entity's types.","commonSituations":"Requesting a deleted record; wrong IRI/key passed by the client; filtering by a type the entity was never saved as; working against a different database than expected.","solutions":["Check schema.IsNotFound(err) and handle it as 'entity missing' (create it, return 404, etc.).","Verify the node ID/name exists via a direct quad query before loading.","Confirm the entity was saved with the expected rdf type (schema.WriteAll or with type constraint)."],"exampleFix":"// before\nerr := schema.LoadTo(ctx, qs, &person, iri)\nlog.Fatal(err) // crashes on missing entity\n// after\nif err := schema.LoadTo(ctx, qs, &person, iri); err != nil {\n    if schema.IsNotFound(err) {\n        return nil, ErrUserNotFound\n    }\n    return nil, err\n}","handlingStrategy":"type-guard","validationCode":"// ensure node exists before load\npqs := graph.NewQuadStoreIterator(qs, iri)\nif !pqs.Next() { return errors.New(\"node does not exist\") }","typeGuard":"func isEntityMissing(err error) bool { return schema.IsNotFound(err) }","tryCatchPattern":"if err := schema.LoadTo(ctx, qs, &v, iri); err != nil {\n    if schema.IsNotFound(err) {\n        return ErrEntityNotFound\n    }\n    return err\n}","preventionTips":["Always branch on schema.IsNotFound after loads","Verify IDs/names against the store before loading","Keep entity types consistent between save and load paths"],"tags":["go","schema","loader","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}