{"record":{"id":"8cfb8ee589ed67a3","repo":"derailed/k9s","slug":"expected-unstructured-but-got-t","errorCode":null,"errorMessage":"expected Unstructured, but got %T","messagePattern":"expected Unstructured, but got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/render/pv.go","lineNumber":74,"sourceCode":"\tmodel1.HeaderColumn{Name: \"NAME\"},\n\tmodel1.HeaderColumn{Name: \"CAPACITY\", Attrs: model1.Attrs{Capacity: true}},\n\tmodel1.HeaderColumn{Name: \"ACCESS MODES\"},\n\tmodel1.HeaderColumn{Name: \"RECLAIM POLICY\"},\n\tmodel1.HeaderColumn{Name: \"STATUS\"},\n\tmodel1.HeaderColumn{Name: \"CLAIM\"},\n\tmodel1.HeaderColumn{Name: \"STORAGECLASS\"},\n\tmodel1.HeaderColumn{Name: \"REASON\"},\n\tmodel1.HeaderColumn{Name: \"VOLUMEMODE\", Attrs: model1.Attrs{Wide: true}},\n\tmodel1.HeaderColumn{Name: \"LABELS\", Attrs: model1.Attrs{Wide: true}},\n\tmodel1.HeaderColumn{Name: \"VALID\", Attrs: model1.Attrs{Wide: true}},\n\tmodel1.HeaderColumn{Name: \"AGE\", Attrs: model1.Attrs{Time: true}},\n}\n\n// Render renders a K8s resource to screen.\nfunc (p PersistentVolume) Render(o any, _ string, row *model1.Row) error {\n\traw, ok := o.(*unstructured.Unstructured)\n\tif !ok {\n\t\treturn fmt.Errorf(\"expected Unstructured, but got %T\", o)\n\t}\n\tif err := p.defaultRow(raw, row); err != nil {\n\t\treturn err\n\t}\n\tif p.specs.isEmpty() {\n\t\treturn nil\n\t}\n\tcols, err := p.specs.realize(raw, defaultPVHeader, row)\n\tcols.hydrateRow(row)\n\n\treturn err\n}\n\nfunc (p PersistentVolume) defaultRow(raw *unstructured.Unstructured, r *model1.Row) error {\n\tvar pv v1.PersistentVolume\n\terr := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &pv)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/render/pv.go#L56-L92","documentation":"PersistentVolume.Render follows the k9s renderer contract: cluster objects must arrive as *unstructured.Unstructured so defaultRow can fill base columns and the custom-column engine (p.specs.realize against defaultPVHeader) can walk the raw JSON. The comma-ok assertion on the any-typed parameter fails and returns this error with the concrete %T when any other Go type reaches the renderer. It signals a wiring bug — the wrong payload type was delivered to the PV renderer — not a cluster problem.","triggerScenarios":"Calling PersistentVolume{}.Render with a typed *v1.PersistentVolume, a map[string]any, a value unstructured.Unstructured (the assertion is on the pointer), or a synthetic row type; binding the pv renderer to another GVR in a custom view; pre-converting informer objects to typed structs before rendering.","commonSituations":"Writing k9s plugins or custom views that register renderers per GVR; refactoring a view to feed typed client-go objects; unit tests with typed fixtures; reusing the PV renderer for a volume-like CRD.","solutions":["Pass the informer-cached object untouched as *unstructured.Unstructured","Convert typed objects first: runtime.DefaultUnstructuredConverter.ToUnstructured(&typedObj), then wrap in &unstructured.Unstructured{Object: m}","Verify the view factory binds PersistentVolume only to the PV GVR","Guard custom call sites with a comma-ok check and skip the row on mismatch"],"exampleFix":"// before\ntyped := &v1.PersistentVolume{}\nerr := pvRenderer.Render(typed, ns, row)\n// after\nm, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(typed)\nerr := pvRenderer.Render(&unstructured.Unstructured{Object: m}, ns, row)","handlingStrategy":"type-guard","validationCode":"// gate before invoking the PV renderer\nif _, ok := o.(*unstructured.Unstructured); !ok {\n\treturn fmt.Errorf(\"pv view requires *unstructured.Unstructured, got %T\", o)\n}\nerr := pvRenderer.Render(o, ns, row)","typeGuard":"func isUnstructured(o any) bool {\n\t_, ok := o.(*unstructured.Unstructured)\n\treturn ok\n}","tryCatchPattern":"if err := pvRenderer.Render(o, ns, row); err != nil {\n\tslog.Warn(\"pv row skipped\", \"type\", fmt.Sprintf(\"%T\", o), slogs.Error, err)\n\treturn nil // drop the row, keep the view alive\n}","preventionTips":["Register each renderer with exactly one GVR in the view factory","Deliver informer-cache objects to Render untouched as *unstructured.Unstructured","Convert typed objects with runtime.DefaultUnstructuredConverter before rendering","Unit-test Render with the exact asserted type (pointer, not value)"],"tags":["kubernetes","go","type-assertion","persistent-volume","storage","renderer","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}