cayleygraph/cayley · error · DeltaError

ErrInvalidAction

ErrInvalidAction

Error message

invalid action

What it means

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.

Source

Thrown at graph/quadwriter.go:85

type Handle struct {
	QuadStore
	QuadWriter
}

type IgnoreOpts struct {
	IgnoreDup, IgnoreMissing bool
}

func (h *Handle) Close() error {
	err := h.QuadWriter.Close()
	h.QuadStore.Close()
	return err
}

var (
	ErrQuadExists    = errors.New("quad exists")
	ErrQuadNotExist  = errors.New("quad does not exist")
	ErrInvalidAction = errors.New("invalid action")
	ErrNodeNotExists = errors.New("node does not exist")
)

// DeltaError records an error and the delta that caused it.
type DeltaError struct {
	Delta Delta
	Err   error
}

func (e *DeltaError) Error() string {
	if !e.Delta.Quad.IsValid() {
		return e.Err.Error()
	}
	return e.Delta.Action.String() + " " + e.Delta.Quad.String() + ": " + e.Err.Error()
}

func (e *DeltaError) Unwrap() error {
	return e.Err

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Set Delta.Action explicitly to graph.Add or graph.Delete when constructing each delta
  2. Check the Delta struct was not built with a zero value; use graph.NewDelta or fill in Action before ApplyDeltas
  3. Compare the incoming action against graph.Add/graph.Delete before submitting and drop unknown actions
  4. Inspect the returned graph.DeltaError to find and correct the specific bad delta

Example fix

// before
deltas = append(deltas, graph.Delta{Quad: q})
// after
deltas = append(deltas, graph.Delta{Quad: q, Action: graph.Add})
Defensive patterns

Strategy: validation

Validate before calling

for i, d := range deltas {
    if d.Action != graph.Add && d.Action != graph.Delete {
        return fmt.Errorf("delta %d: invalid action %v", i, d.Action)
    }
}

Try / catch

err := qw.ApplyDeltas(deltas)
if err != nil {
    var de *graph.DeltaError
    if errors.As(err, &de) && errors.Is(de.Err, graph.ErrInvalidAction) {
        // inspect de.Delta.Action and fix the offending delta
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/230d94a69b5ecb62. Report an issue: GitHub.