{"record":{"id":"7ee8d22391da29a5","repo":"derailed/k9s","slug":"no-benchmark-dir-found-in-context","errorCode":null,"errorMessage":"no benchmark dir found in context","messagePattern":"no benchmark dir found in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/benchmark.go","lineNumber":46,"sourceCode":"type Benchmark struct {\n\tNonResource\n}\n\n// Delete nukes a resource.\nfunc (*Benchmark) Delete(_ context.Context, path string, _ *metav1.DeletionPropagation, _ Grace) error {\n\treturn os.Remove(path)\n}\n\n// Get returns a resource.\nfunc (*Benchmark) Get(context.Context, string) (runtime.Object, error) {\n\tpanic(\"NYI\")\n}\n\n// List returns a collection of resources.\nfunc (*Benchmark) 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 benchmark dir found in context\")\n\t}\n\tpath, ok := ctx.Value(internal.KeyPath).(string)\n\tif !ok {\n\t\treturn nil, errors.New(\"no path specified in context\")\n\t}\n\tpathMatch := BenchRx.ReplaceAllString(strings.Replace(path, \"/\", \"_\", 1), \"_\")\n\n\tff, err := os.ReadDir(dir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\too := make([]runtime.Object, 0, len(ff))\n\tfor _, f := range ff {\n\t\tif !strings.HasPrefix(f.Name(), pathMatch) {\n\t\t\tcontinue\n\t\t}\n\t\tif fi, err := f.Info(); err == nil {\n\t\t\too = append(oo, render.BenchInfo{File: fi, Path: filepath.Join(dir, f.Name())})","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/benchmark.go#L28-L64","documentation":"Returned by Benchmark DAO List (internal/dao/benchmark.go:46) when the context.Context passed to List lacks the internal.KeyDir value (a string). The benchmark feature reads profiling/census benchmark files from a directory supplied via context; KeyDir points at the directory containing the benchmark output files. Missing key means List was invoked outside the benchmark view plumbing that injects it.","triggerScenarios":"Calling dao Benchmark.List(ctx, ...) with a plain context.Background()/TODO, or any path that forgets context.WithValue(ctx, internal.KeyDir, dir); also if the value stored is not a string (type assertion !ok).","commonSituations":"Reusing the DAO layer from custom code or tests without replicating the view's context enrichment; refactors that dropped the WithValue calls; invoking List programmatically for tooling.","solutions":["Inject the benchmark directory before listing: ctx = context.WithValue(ctx, internal.KeyDir, dir) using the same internal key package the views use","Prefer calling through the benchmark view/factory so the context is assembled correctly","In tests, build the context exactly as view/benchmark.go does (KeyDir + KeyPath)","Copy the pattern from existing callers: search for KeyDir usages and mirror them"],"exampleFix":"// before\nbench := dao.Benchmark{}\noo, err := bench.List(context.Background(), \"\")\n\n// after\nctx := context.WithValue(context.Background(), internal.KeyDir, \"/tmp/bench\")\nctx = context.WithValue(ctx, internal.KeyPath, \"cpu/profile\")\noo, err := bench.List(ctx, \"\")","handlingStrategy":"validation","validationCode":"func withBenchDir(ctx context.Context, dir string) context.Context {\n    return context.WithValue(ctx, internal.KeyDir, dir)\n}\n// call sites always use the helper","typeGuard":null,"tryCatchPattern":"oo, err := benchDao.List(ctx, \"\")\nif err != nil && strings.Contains(err.Error(), \"no benchmark dir found in context\") {\n    // re-build ctx with KeyDir and retry once\n}","preventionTips":["Wrap DAO calls with a context-builder helper that sets both KeyDir and KeyPath","Never pass context.Background() straight into DAO List","Keep benchmark-directory wiring in one place (the view layer)"],"tags":["go","context","k9s","benchmarks","dao"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}