{"record":{"id":"9d7d4a837ab32d99","repo":"wagoodman/dive","slug":"unable-to-set-view-to-layer-q-w","errorCode":null,"errorMessage":"unable to set view to layer %q: %w","messagePattern":"unable to set view to layer %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/ui/v1/layout/compound/layer_details_column.go","lineNumber":88,"sourceCode":"func (cl *LayerDetailsCompoundLayout) Layout(g *gocui.Gui, minX, minY, maxX, maxY int) error {\n\tlog.WithFields(\"ui\", cl.Name()).Tracef(\"layout(minX: %d, minY: %d, maxX: %d, maxY: %d)\", minX, minY, maxX, maxY)\n\n\tlayouts := []view.View{\n\t\tcl.layer,\n\t\tcl.layerDetails,\n\t\tcl.imageDetails,\n\t}\n\n\trowHeight := maxY / 3\n\tfor i := 0; i < 3; i++ {\n\t\tif err := cl.layoutRow(g, minX, i*rowHeight, maxX, (i+1)*rowHeight, layouts[i].Name(), layouts[i].Setup); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to layout %q: %w\", layouts[i].Name(), err)\n\t\t}\n\t}\n\n\tif g.CurrentView() == nil {\n\t\tif _, err := g.SetCurrentView(cl.layer.Name()); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to set view to layer %q: %w\", cl.layer.Name(), err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (cl *LayerDetailsCompoundLayout) RequestedSize(available int) *int {\n\t// \"available\" is the entire screen real estate, so we can guess when its a bit too small and take action.\n\t// This isn't perfect, but it gets the job done for now without complicated layout constraint solvers\n\tif available < 90 {\n\t\tcl.layer.ConstrainLayout()\n\t\tcl.constrainRealEstate = true\n\t\tsize := 8\n\t\treturn &size\n\t}\n\tcl.layer.ExpandLayout()\n\tcl.constrainRealEstate = false\n\treturn nil\n}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/ui/v1/layout/compound/layer_details_column.go#L70-L106","documentation":"Raised when dive tries to make the 'layer' view the current (focused) view via gocui's Gui.SetCurrentView and gocui rejects it. It only executes when g.CurrentView() == nil, i.e. on the very first layout pass before any view has focus. SetCurrentView fails when the named view does not exist yet (not created by a prior SetView) or was deleted.","triggerScenarios":"Gui.SetCurrentView(\"layer\") returning a non-nil error: the 'layer' view was never created because its layoutRow/SetView failed earlier in the same pass, the view was deleted by g.DeleteView elsewhere, or the view name registered by layoutRow does not match cl.layer.Name().","commonSituations":"A preceding layoutRow failure left the layer view missing; concurrent GUI teardown during Ctrl+C while a layout pass is in flight; custom builds that rename views or add views that steal/delete the layer view; race between gui.MainLoop shutdown and a queued layout.","solutions":["Look at the error just before this one in the log — a failed layoutRow for the layer view is the usual root cause; fix that first","Verify no code path calls g.DeleteView on the layer view while the layout manager still runs","On shutdown races, ensure gui.MainLoop has fully returned before tearing down view state","Enlarge terminal / fix geometry so all three column views are created successfully"],"exampleFix":"// ensure the layer view exists before focusing it\nif _, err := g.View(cl.layer.Name()); err == nil {\n    if _, err := g.SetCurrentView(cl.layer.Name()); err != nil {\n        return fmt.Errorf(\"unable to set view to layer %q: %w\", cl.layer.Name(), err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"// verify the view exists before focusing it\nif _, err := g.View(cl.layer.Name()); err != nil {\n    return nil // view not created yet; skip focus this pass\n}","typeGuard":null,"tryCatchPattern":"if _, err := g.SetCurrentView(cl.layer.Name()); err != nil {\n    if errors.Is(err, gocui.ErrUnknownView) {\n        // benign on first pass; retry next layout\n        return nil\n    }\n    return fmt.Errorf(\"unable to set view to layer %q: %w\", cl.layer.Name(), err)\n}","preventionTips":["Create the layer view before any code path can call SetCurrentView","Avoid deleting views while the layout manager is active","Treat ErrUnknownView during startup as retryable on the next layout pass"],"tags":["ui","gocui","focus","startup"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}