{"record":{"id":"095f8a00a9c6292b","repo":"derailed/k9s","slug":"no-screendump-dir-found-in-context","errorCode":null,"errorMessage":"no screendump dir found in context","messagePattern":"no screendump dir found in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/screen_dump.go","lineNumber":36,"sourceCode":"\t_ Accessor = (*ScreenDump)(nil)\n\t_ Nuker    = (*ScreenDump)(nil)\n)\n\n// ScreenDump represents a scraped resources.\ntype ScreenDump struct {\n\tNonResource\n}\n\n// Delete a ScreenDump.\nfunc (*ScreenDump) Delete(_ context.Context, path string, _ *metav1.DeletionPropagation, _ Grace) error {\n\treturn os.Remove(path)\n}\n\n// List returns a collection of screen dumps.\nfunc (*ScreenDump) List(ctx context.Context, _ string) ([]runtime.Object, error) {\n\tdir, ok := ctx.Value(internal.KeyDir).(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"no screendump dir found in context\")\n\t}\n\n\tff, err := os.ReadDir(dir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\too := make([]runtime.Object, len(ff))\n\tfor i, f := range ff {\n\t\tif fi, err := f.Info(); err == nil {\n\t\t\too[i] = render.FileRes{File: fi, Dir: dir}\n\t\t}\n\t}\n\n\treturn oo, nil\n}\n","sourceCodeStart":18,"sourceCodeEnd":52,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/screen_dump.go#L18-L52","documentation":"ScreenDump.List lists the .png files k9s writes when you take screen captures; the directory is taken from ctx.Value(internal.KeyDir), which view/screen_dump.go:45 sets from the configured screen-dump dir. If the DAO is called with a context lacking that key, there is no directory to read and the call fails before os.ReadDir.","triggerScenarios":"Calling dao ScreenDump.List with a bare context (no context.WithValue(ctx, internal.KeyDir, dir)); storing a non-string under KeyDir.","commonSituations":"Unit/integration tests or custom code driving the DAO directly; a custom view that replicates the screen-dump browser but forgets the dir injection; renaming the ContextKey so producer and consumer disagree.","solutions":["Inject the dir before listing: ctx = context.WithValue(ctx, internal.KeyDir, dir) mirroring internal/view/screen_dump.go:45.","Derive the dir from configuration the same way the shipped view does (screen dump dir from config), so it points at where captures are actually written.","For tests, seed the context like dao/benchmark_test.go:22 does with KeyDir."],"exampleFix":"// before\noo, err := sd.List(context.Background(), \"\") // -> no screendump dir found in context\n// after\ndir := cfg.ScreenDumpDir()\nctx := context.WithValue(context.Background(), internal.KeyDir, dir)\noo, err := sd.List(ctx, \"\")","handlingStrategy":"validation","validationCode":"if _, ok := ctx.Value(internal.KeyDir).(string); !ok {\n    ctx = context.WithValue(ctx, internal.KeyDir, cfg.ScreenDumpDir())\n}\noo, err := screenDumpDAO.List(ctx, \"\")","typeGuard":"func dirFromCtx(ctx context.Context) (string, bool) {\n    d, ok := ctx.Value(internal.KeyDir).(string)\n    return d, ok\n}","tryCatchPattern":null,"preventionTips":["Mirror internal/view/screen_dump.go:45 when building custom screen-dump views.","Ensure the configured dir exists and is writable so List has something to read.","Keep ContextKey names in sync between producer and consumer packages."],"tags":["go","kubernetes","context","screendump","dao"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}