{"record":{"id":"caaab1c94ed63e01","repo":"krahets/hello-algo","slug":"error-caaab1","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/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/ja/codes/go/chapter_graph/graph_adjacency_list.go#L27-L63","documentation":"`addEdge(vet1, vet2)` in the Japanese `graphAdjList` panics with \"error\" when an endpoint is missing from the adjacency map or the two endpoints are identical. The undirected model forbids self-loops and requires both vertices to exist.","triggerScenarios":"`addEdge` on a vertex not added via `addVertex`; `addEdge(v, v)`; building an edge before registering vertices.","commonSituations":"Edge data loaded without the vertex set, self-loop entries, or a typo making one endpoint unknown.","solutions":["Register both endpoints with `addVertex` first.","Filter self-loops (`vet1 != vet2`).","Assert existence via `hasVertex`.","Recover when ingesting untrusted edges."],"exampleFix":"// before\ng.addEdge(a, b) // panic if missing endpoint or a == b\n\n// after\nif hasVertex(g, a) && hasVertex(g, b) && a != b {\n    g.addEdge(a, b)\n}","handlingStrategy":"validation","validationCode":"if !hasVertex(g, vet1) || !hasVertex(g, vet2) || vet1 == vet2 {\n    return errors.New(\"endpoints missing or self-loop\")\n}\ng.addEdge(vet1, vet2)","typeGuard":"func hasVertex(g *graphAdjList, v Vertex) bool {\n    _, ok := g.adjList[v]\n    return ok\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        // skip the offending edge and continue ingestion\n    }\n}()\ng.addEdge(vet1, vet2)","preventionTips":["addVertex for both endpoints before addEdge.","Sanitize imported data: drop self-loops and unknown vertices.","Wrap bulk ingestion in recover."],"tags":["go","graph","adjacency-list","panic","teaching-example"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}