{"record":{"id":"3a343d771b0f283e","repo":"projectdiscovery/katana","slug":"could-not-add-edge-to-graph","errorCode":null,"errorMessage":"could not add edge to graph","messagePattern":"could not add edge to graph","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/graph/graph.go","lineNumber":100,"sourceCode":"func (g *CrawlGraph) AddEdge(sourceState, targetState string, action *types.Action) error {\n\tif action == nil {\n\t\treturn errors.New(\"add edge: action cannot be nil\")\n\t}\n\tedgeAttrs := map[string]string{\n\t\t\"label\": action.String(),\n\t}\n\terr := g.graph.AddEdge(sourceState, targetState, func(ep *graph.EdgeProperties) {\n\t\tep.Weight = action.Depth\n\t\tep.Attributes = edgeAttrs\n\t})\n\tif err != nil {\n\t\tif errors.Is(err, graph.ErrEdgeAlreadyExists) {\n\t\t\treturn nil\n\t\t}\n\t\treturn errors.Wrap(err, \"could not add edge to graph\")\n\t}\n\treturn nil\n}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/graph/graph.go#L82-L118","documentation":"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.","triggerScenarios":"Thrown at pkg/engine/headless/graph/graph.go:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify both sourceState and targetState vertices exist via AddPageState before calling AddEdge","Handle only ErrEdgeAlreadyExists as success; surface other graph errors to the caller","Log sourceState/targetState hashes to identify the missing endpoint","Guard against concurrent mutation of the graph if edges are added from multiple goroutines"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}