{"record":{"id":"76f5d56ff4f9012d","repo":"TheAlgorithms/Go","slug":"coloring-not-all-vertices-of-graph-are-colored","errorCode":null,"errorMessage":"coloring: not all vertices of graph are colored","messagePattern":"coloring: not all vertices of graph are colored","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/coloring/graph.go","lineNumber":46,"sourceCode":"\t\tg.vertices++\n\t\tg.edges[v] = make(map[int]struct{})\n\t}\n}\n\n// AddEdge will add a new edge between the provided vertices in the graph\nfunc (g *Graph) AddEdge(one, two int) {\n\t// Add vertices: one and two to the graph if they are not present\n\tg.AddVertex(one)\n\tg.AddVertex(two)\n\n\t// and finally add the edges: one->two and two->one for undirected graph\n\tg.edges[one][two] = struct{}{}\n\tg.edges[two][one] = struct{}{}\n}\n\nfunc (g *Graph) ValidateColorsOfVertex(colors map[int]Color) error {\n\tif g.vertices != len(colors) {\n\t\treturn errors.New(\"coloring: not all vertices of graph are colored\")\n\t}\n\t// check colors\n\tfor vertex, neighbours := range g.edges {\n\t\tfor nb := range neighbours {\n\t\t\tif colors[vertex] == colors[nb] {\n\t\t\t\treturn errors.New(\"coloring: same colors of neighbouring vertex\")\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":28,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/graph/coloring/graph.go#L28-L58","documentation":"ValidateColorsOfVertex compares the graph's vertex count with len(colors); a mismatch means the colors map doesn't cover every vertex (or covers extra/unknown vertex ids), so validity can't be assessed.","triggerScenarios":"Thrown at graph/coloring/graph.go:46 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Build the colors map by iterating all graph vertices before validating","Ensure vertices are added via AddVertex/AddEdge before assigning colors","Call BipartiteCheck/ValidateColorsOfVertex only after the graph is fully constructed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}