{"record":{"id":"7c677ca86e7dc9c2","repo":"krahets/hello-algo","slug":"error-7c677c","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/go/chapter_graph/graph_adjacency_list.go","lineNumber":45,"sourceCode":"\tfor _, edge := range edges {\n\t\tg.addVertex(edge[0])\n\t\tg.addVertex(edge[1])\n\t\tg.addEdge(edge[0], edge[1])\n\t}\n\treturn g\n}\n\n/* Получить число вершин */\nfunc (g *graphAdjList) size() int {\n\treturn len(g.adjList)\n}\n\n/* Добавление ребра */\nfunc (g *graphAdjList) addEdge(vet1 Vertex, vet2 Vertex) {\n\t_, ok1 := g.adjList[vet1]\n\t_, ok2 := g.adjList[vet2]\n\tif !ok1 || !ok2 || vet1 == vet2 {\n\t\tpanic(\"error\")\n\t}\n\t// Добавить ребро vet1 - vet2, добавив анонимную struct{}\n\tg.adjList[vet1] = append(g.adjList[vet1], vet2)\n\tg.adjList[vet2] = append(g.adjList[vet2], vet1)\n}\n\n/* Удаление ребра */\nfunc (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) {\n\t_, ok1 := g.adjList[vet1]\n\t_, ok2 := g.adjList[vet2]\n\tif !ok1 || !ok2 || vet1 == vet2 {\n\t\tpanic(\"error\")\n\t}\n\t// Удалить ребро vet1 - vet2\n\tg.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2)\n\tg.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1)\n}\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/go/chapter_graph/graph_adjacency_list.go#L27-L63","documentation":"Panic thrown by addEdge(vet1, vet2) on the undirected adjacency-list graph when the operation is illegal. The guard aborts if either endpoint vertex is not present in the adjacency map, or if both arguments are the same vertex (self-loops are disallowed). This keeps the graph representation consistent: an edge can only connect two distinct, pre-registered vertices.","triggerScenarios":"Calling addEdge() with a vertex that was never added via addVertex(); passing vet1 == vet2; adding an edge whose endpoint was previously removeVertex()'d.","commonSituations":"Building a graph from raw edge data and forgetting to register vertices first; reusing a graph instance after removing a vertex but still referencing it in edge calls; assuming the constructor registered a vertex that was actually skipped.","solutions":["Call addVertex() for both endpoints before addEdge().","Guard the call: confirm both vertices exist and are distinct (vet1 != vet2).","When loading edges, deduplicate/register all distinct vertices in a first pass, then add edges.","After any removeVertex(), stop issuing edge calls that reference the removed vertex."],"exampleFix":"// before: panics if a vertex is missing or vet1 == vet2\ng.addEdge(a, b)\n\n// after: ensure vertices exist and differ\nif a != b {\n    g.addVertex(a)\n    g.addVertex(b)\n    g.addEdge(a, b)\n}","handlingStrategy":"validation","validationCode":"// Membership helper (adjList is unexported; expose a method on the type).\nfunc (g *graphAdjList) hasVertex(v Vertex) bool {\n    _, ok := g.adjList[v]\n    return ok\n}\n\nif vet1 != vet2 && g.hasVertex(vet1) && g.hasVertex(vet2) {\n    g.addEdge(vet1, vet2)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        // edge rejected: missing vertex or self-loop\n    }\n}()\ng.addEdge(vet1, vet2)","preventionTips":["Register every distinct vertex with addVertex() before any addEdge().","Reject or skip self-loop edges (vet1 == vet2) upstream.","Build graphs in two passes: vertices first, then edges."],"tags":["go","graph","adjacency-list","addedge","validation"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}