{"record":{"id":"758251ecaf5ca8af","repo":"derailed/k9s","slug":"expected-unstructured-but-got-t-758251","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/sa.go","lineNumber":40,"sourceCode":"\tmodel1.HeaderColumn{Name: \"VALID\", Attrs: model1.Attrs{Wide: true}},\n\tmodel1.HeaderColumn{Name: \"AGE\", Attrs: model1.Attrs{Time: true}},\n}\n\n// ServiceAccount renders a K8s ServiceAccount to screen.\ntype ServiceAccount struct {\n\tBase\n}\n\n// Header returns a header row.\nfunc (s ServiceAccount) Header(_ string) model1.Header {\n\treturn s.doHeader(defaultSAHeader)\n}\n\n// Render renders a K8s resource to screen.\nfunc (s ServiceAccount) 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 := s.defaultRow(raw, row); err != nil {\n\t\treturn err\n\t}\n\tif s.specs.isEmpty() {\n\t\treturn nil\n\t}\n\tcols, err := s.specs.realize(raw, defaultSAHeader, row)\n\tcols.hydrateRow(row)\n\n\treturn err\n}\n\nfunc (ServiceAccount) defaultRow(raw *unstructured.Unstructured, r *model1.Row) error {\n\tvar sa v1.ServiceAccount\n\terr := runtime.DefaultUnstructuredConverter.FromUnstructured(raw.Object, &sa)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/render/sa.go#L22-L58","documentation":"ServiceAccount.Render implements the k9s renderer contract for serviceaccount rows: the object must be *unstructured.Unstructured so defaultRow can fill base columns and the custom-column engine (s.specs.realize against defaultSAHeader) can walk the raw JSON. The comma-ok assertion fails and returns this error, printing the concrete %T, when any other Go type reaches the renderer — a wiring bug in the caller.","triggerScenarios":"Calling ServiceAccount{}.Render with a typed *v1.ServiceAccount, a map[string]any, a value unstructured.Unstructured, or a synthetic row type; binding the sa renderer to a different GVR in a custom view factory.","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 ServiceAccount only to the SA GVR","Guard custom call sites with a comma-ok check and skip the row on mismatch"],"exampleFix":"// before\ntyped := &v1.ServiceAccount{}\nerr := saRenderer.Render(typed, ns, row)\n// after\nm, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(typed)\nerr := saRenderer.Render(&unstructured.Unstructured{Object: m}, ns, row)","handlingStrategy":"type-guard","validationCode":"// gate before invoking the ServiceAccount renderer\nif _, ok := o.(*unstructured.Unstructured); !ok {\n\treturn fmt.Errorf(\"sa view requires *unstructured.Unstructured, got %T\", o)\n}\nerr := saRenderer.Render(o, ns, row)","typeGuard":"func isUnstructured(o any) bool {\n\t_, ok := o.(*unstructured.Unstructured)\n\treturn ok\n}","tryCatchPattern":"if err := saRenderer.Render(o, ns, row); err != nil {\n\tslog.Warn(\"sa 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","service-account","rbac","renderer","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}