{"record":{"id":"87943e8533d7eebf","repo":"derailed/k9s","slug":"expected-unstructured-but-got-t-87943e","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/pvc.go","lineNumber":43,"sourceCode":"\tmodel1.HeaderColumn{Name: \"VALID\", Attrs: model1.Attrs{Wide: true}},\n\tmodel1.HeaderColumn{Name: \"AGE\", Attrs: model1.Attrs{Time: true}},\n}\n\n// PersistentVolumeClaim renders a K8s PersistentVolumeClaim to screen.\ntype PersistentVolumeClaim struct {\n\tBase\n}\n\n// Header returns a header row.\nfunc (p PersistentVolumeClaim) Header(_ string) model1.Header {\n\treturn p.doHeader(defaultPVCHeader)\n}\n\n// Render renders a K8s resource to screen.\nfunc (p PersistentVolumeClaim) 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\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\n\tcols, err := p.specs.realize(raw, defaultPVCHeader, row)\n\tcols.hydrateRow(row)\n\n\treturn err\n}\n\nfunc (p PersistentVolumeClaim) defaultRow(raw *unstructured.Unstructured, r *model1.Row) error {\n\tvar pvc v1.PersistentVolumeClaim\n\terr := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &pvc)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/render/pvc.go#L25-L61","documentation":"PersistentVolumeClaim.Render follows the k9s renderer contract: the object must be *unstructured.Unstructured so defaultRow can populate base columns and p.specs.realize can apply custom columns from defaultPVCHeader against the raw JSON. The comma-ok assertion fails and returns this error (printing the concrete %T) when any other Go type is passed. It indicates the PVC renderer received a wrongly-typed payload — a wiring bug in the caller, not a cluster issue.","triggerScenarios":"Calling PersistentVolumeClaim{}.Render with typed *v1.PersistentVolumeClaim objects, map[string]any, a value unstructured.Unstructured, or synthetic row types; mapping the pvc renderer to a different GVR in a custom view factory; pre-converting informer objects to typed structs.","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.","solutions":["Pass the informer-cached object untouched as *unstructured.Unstructured","Convert typed objects with runtime.DefaultUnstructuredConverter.ToUnstructured and wrap in &unstructured.Unstructured{Object: m}","Verify the view factory binds PersistentVolumeClaim only to the PVC GVR","Guard custom call sites with a comma-ok check and skip the row on mismatch"],"exampleFix":"// before\ntyped := &v1.PersistentVolumeClaim{}\nerr := pvcRenderer.Render(typed, ns, row)\n// after\nm, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(typed)\nerr := pvcRenderer.Render(&unstructured.Unstructured{Object: m}, ns, row)","handlingStrategy":"type-guard","validationCode":"// gate before invoking the PVC renderer\nif _, ok := o.(*unstructured.Unstructured); !ok {\n\treturn fmt.Errorf(\"pvc view requires *unstructured.Unstructured, got %T\", o)\n}\nerr := pvcRenderer.Render(o, ns, row)","typeGuard":"func isUnstructured(o any) bool {\n\t_, ok := o.(*unstructured.Unstructured)\n\treturn ok\n}","tryCatchPattern":"if err := pvcRenderer.Render(o, ns, row); err != nil {\n\tslog.Warn(\"pvc 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","pvc","storage","renderer","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}