{"record":{"id":"230d94a69b5ecb62","repo":"cayleygraph/cayley","slug":"errinvalidaction","errorCode":"ErrInvalidAction","errorMessage":"invalid action","messagePattern":"invalid action","errorType":"error_code","errorClass":"DeltaError","httpStatus":null,"severity":"error","filePath":"graph/quadwriter.go","lineNumber":85,"sourceCode":"type Handle struct {\n\tQuadStore\n\tQuadWriter\n}\n\ntype IgnoreOpts struct {\n\tIgnoreDup, IgnoreMissing bool\n}\n\nfunc (h *Handle) Close() error {\n\terr := h.QuadWriter.Close()\n\th.QuadStore.Close()\n\treturn err\n}\n\nvar (\n\tErrQuadExists    = errors.New(\"quad exists\")\n\tErrQuadNotExist  = errors.New(\"quad does not exist\")\n\tErrInvalidAction = errors.New(\"invalid action\")\n\tErrNodeNotExists = errors.New(\"node does not exist\")\n)\n\n// DeltaError records an error and the delta that caused it.\ntype DeltaError struct {\n\tDelta Delta\n\tErr   error\n}\n\nfunc (e *DeltaError) Error() string {\n\tif !e.Delta.Quad.IsValid() {\n\t\treturn e.Err.Error()\n\t}\n\treturn e.Delta.Action.String() + \" \" + e.Delta.Quad.String() + \": \" + e.Err.Error()\n}\n\nfunc (e *DeltaError) Unwrap() error {\n\treturn e.Err","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/quadwriter.go#L67-L103","documentation":"ErrInvalidAction is returned when a delta carries an Action value that the quadstore does not recognize. Valid actions are graph.Add and graph.Delete; anything else (including the zero value of DeltaAction) is rejected. It is usually wrapped in a graph.DeltaError naming the offending delta.","triggerScenarios":"Calling ApplyDeltas or WriteQuad with a Delta whose Action is neither Add nor Delete; passing an uninitialized Delta struct (Action defaults to 0, which is not a valid action); memstore ApplyDeltas hitting the default branch in both add and remove switch statements.","commonSituations":"Building deltas programmatically with a custom/wrong action constant; forgetting to set Action on a constructed Delta; switching on DeltaAction with values from an older Cayley version where the enum changed.","solutions":["Set Delta.Action explicitly to graph.Add or graph.Delete when constructing each delta","Check the Delta struct was not built with a zero value; use graph.NewDelta or fill in Action before ApplyDeltas","Compare the incoming action against graph.Add/graph.Delete before submitting and drop unknown actions","Inspect the returned graph.DeltaError to find and correct the specific bad delta"],"exampleFix":"// before\ndeltas = append(deltas, graph.Delta{Quad: q})\n// after\ndeltas = append(deltas, graph.Delta{Quad: q, Action: graph.Add})","handlingStrategy":"validation","validationCode":"for i, d := range deltas {\n    if d.Action != graph.Add && d.Action != graph.Delete {\n        return fmt.Errorf(\"delta %d: invalid action %v\", i, d.Action)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := qw.ApplyDeltas(deltas)\nif err != nil {\n    var de *graph.DeltaError\n    if errors.As(err, &de) && errors.Is(de.Err, graph.ErrInvalidAction) {\n        // inspect de.Delta.Action and fix the offending delta\n    }\n}","preventionTips":["Always set Action: graph.Add or graph.Delete explicitly on constructed deltas","Never submit a zero-value Delta struct","Validate deltas against known actions before ApplyDeltas","Audit enum usage after Cayley version upgrades"],"tags":["graph","delta","enum","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}