projectdiscovery/katana · error

could not add edge to graph

Error message

could not add edge to graph

What it means

CrawlGraph.AddEdge fails when graph.AddEdge(sourceState, targetState, ...) returns an error other than graph.ErrEdgeAlreadyExists (which is accepted as a no-op). Typically a source or target vertex is missing from the crawl graph, or the edge would be invalid, so the navigation relationship cannot be recorded.

Source

Thrown at pkg/engine/headless/graph/graph.go:100

func (g *CrawlGraph) AddEdge(sourceState, targetState string, action *types.Action) error {
	if action == nil {
		return errors.New("add edge: action cannot be nil")
	}
	edgeAttrs := map[string]string{
		"label": action.String(),
	}
	err := g.graph.AddEdge(sourceState, targetState, func(ep *graph.EdgeProperties) {
		ep.Weight = action.Depth
		ep.Attributes = edgeAttrs
	})
	if err != nil {
		if errors.Is(err, graph.ErrEdgeAlreadyExists) {
			return nil
		}
		return errors.Wrap(err, "could not add edge to graph")
	}
	return nil
}

View on GitHub (pinned to e3e742739c)

Solutions

  1. Verify both sourceState and targetState vertices exist via AddPageState before calling AddEdge
  2. Handle only ErrEdgeAlreadyExists as success; surface other graph errors to the caller
  3. Log sourceState/targetState hashes to identify the missing endpoint
  4. Guard against concurrent mutation of the graph if edges are added from multiple goroutines
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/engine/headless/graph/graph.go:100 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of projectdiscovery/katana@e3e742739c (2026-09-03). Data as JSON: /api/errors/3a343d771b0f283e. Report an issue: GitHub.