{"record":{"id":"163200cd15c18187","repo":"derailed/k9s","slug":"no-application-found-in-context","errorCode":null,"errorMessage":"no application found in context","messagePattern":"no application found in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/helpers.go","lineNumber":174,"sourceCode":"\tif err := app.Config.SetActiveNamespace(ns); err != nil {\n\t\tslog.Error(\"Unable to set active namespace during show pods\", slogs.Error, err)\n\t}\n\tif err := app.inject(v, false); err != nil {\n\t\tapp.Flash().Err(err)\n\t}\n}\n\nfunc podCtx(_ *App, path, fieldSel string) ContextFunc {\n\treturn func(ctx context.Context) context.Context {\n\t\tctx = context.WithValue(ctx, internal.KeyPath, path)\n\t\treturn context.WithValue(ctx, internal.KeyFields, fieldSel)\n\t}\n}\n\nfunc extractApp(ctx context.Context) (*App, error) {\n\tapp, ok := ctx.Value(internal.KeyApp).(*App)\n\tif !ok {\n\t\treturn nil, errors.New(\"no application found in context\")\n\t}\n\n\treturn app, nil\n}\n\n// AsKey maps a string representation of a key to a tcell key.\nfunc asKey(key string) (tcell.Key, error) {\n\tfor k, v := range tcell.KeyNames {\n\t\tif key == v {\n\t\t\treturn k, nil\n\t\t}\n\t}\n\n\treturn 0, fmt.Errorf(\"invalid key specified: %q\", key)\n}\n\n// FwFQN returns a fully qualified ns/name:container id.\nfunc fwFQN(po, co string) string {","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/helpers.go#L156-L192","documentation":"Returned by `extractApp` (internal/view/helpers.go:~174) when the context passed to a view helper does not carry the application under `internal.KeyApp` (string key \"app\"), or the stored value is not a `*view.App`. The App injects itself in its context function (internal/view/app.go:98: `context.WithValue(ctx, internal.KeyApp, a)`); helpers like browser/describe commands then pull it back out. A bare context (context.Background(), or one built without the app's ContextFn) fails the type assertion.","triggerScenarios":"Calling a helper that uses extractApp with a context that was not produced by the app's context function — e.g. plugins or custom views passing context.Background(), or a context built with a different ContextKey/value type.","commonSituations":"Custom k9s forks/plugins invoking internal/view helpers directly; tests calling helpers without injecting KeyApp; refactors that bypass SetContextFn.","solutions":["Build the context through the app/view's ContextFn so KeyApp is populated before invoking helpers","If calling manually: `ctx = context.WithValue(ctx, internal.KeyApp, app)` with the canonical *view.App instance","In tests, inject a real NewApp(cfg) value under internal.KeyApp (see helpers_test.go pattern)","Pass the App explicitly instead of via context when you control the call sites"],"exampleFix":"// before\nctx := context.Background()\napp, err := extractApp(ctx) // -> no application found in context\n// after\nctx := context.WithValue(context.Background(), internal.KeyApp, myApp)\napp, err := extractApp(ctx)","handlingStrategy":"type-guard","validationCode":"// Build contexts only through the app's ContextFn so KeyApp is set:\nctx = context.WithValue(ctx, internal.KeyApp, app)","typeGuard":"func appFromCtx(ctx context.Context) (*App, bool) {\n    app, ok := ctx.Value(internal.KeyApp).(*App)\n    return app, ok\n}","tryCatchPattern":"app, err := extractApp(ctx)\nif err != nil {\n    slog.Error(\"missing app in context\", slogs.Error, err)\n    return\n}","preventionTips":["Never pass context.Background() to view helpers","Always use SetContextFn/ContextFn chain that injects KeyApp","Prefer passing *App explicitly in new code"],"tags":["go","context","type-assertion","plugins","k9s"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}