{"record":{"id":"c5d1df515be2b742","repo":"kubernetes/kops","slug":"memfs-context-not-initialized","errorCode":null,"errorMessage":"memfs context not initialized","messagePattern":"memfs context not initialized","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/context.go","lineNumber":481,"sourceCode":"\t}\n\n\tbucket := strings.TrimSuffix(u.Host, \"/\")\n\tif bucket == \"\" {\n\t\treturn nil, fmt.Errorf(\"invalid kubernetes vfs path: %q\", p)\n\t}\n\n\tk8sPath := newKubernetesPath(c.k8sContext, bucket, u.Path)\n\treturn k8sPath, nil\n}\n\nfunc (c *VFSContext) buildMemFSPath(p string) (*MemFSPath, error) {\n\tif !strings.HasPrefix(p, \"memfs://\") {\n\t\treturn nil, fmt.Errorf(\"memfs path not recognized: %q\", p)\n\t}\n\tlocation := strings.TrimPrefix(p, \"memfs://\")\n\tif c.memfsContext == nil {\n\t\t// We only initialize this in unit tests etc\n\t\treturn nil, fmt.Errorf(\"memfs context not initialized\")\n\t}\n\tfspath := NewMemFSPath(c.memfsContext, location)\n\treturn fspath, nil\n}\n\nfunc (c *VFSContext) ResetMemfsContext(clusterReadable bool) {\n\tc.memfsContext = NewMemFSContext()\n\tif clusterReadable {\n\t\tc.memfsContext.MarkClusterReadable()\n\t}\n}\n\nfunc (c *VFSContext) buildGCSPath(p string) (*GSPath, error) {\n\tu, err := url.Parse(p)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid google cloud storage path: %q\", p)\n\t}\n","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/context.go#L463-L499","documentation":"The memfs VFS backend requires an initialized MemFSContext, which holds the in-memory file tree and its cluster-readable flag. VFSContext only initializes memfsContext in unit tests (via ResetMemfsContext), so a production/default VFSContext asked to resolve a memfs:// path has no backing store and throws this error.","triggerScenarios":"BuildVfsPath (or ReadLocation treating a memfs:// path) is called on a VFSContext whose memfsContext field is nil — i.e. the context was never initialized with ResetMemfsContext — while the path correctly starts with memfs://.","commonSituations":"Calling BuildVfsPath(\"memfs://...\") in non-test code or in a test that constructed vfs.Context{} directly without calling ResetMemfsContext first; running a code path (e.g. a tool or command) against memfs:// state store outside of unit tests where memfs is unsupported.","solutions":["In test setup, call vfs.Context.ResetMemfsContext(true) (or false) before building memfs:// paths","Use a real backend (s3://, gs://, file://) for non-test workloads — memfs is test-only","If constructing VFSContext manually, initialize the memfsContext field via ResetMemfsContext rather than leaving it nil"],"exampleFix":"// before\np, err := vfs.Context.BuildVfsPath(\"memfs://test\") // panics error: memfs context not initialized\n// after\nvfs.Context.ResetMemfsContext(true)\np, err := vfs.Context.BuildVfsPath(\"memfs://test\")","handlingStrategy":"validation","validationCode":"if strings.HasPrefix(p, \"memfs://\") && !memfsInitialized {\n\treturn fmt.Errorf(\"call vfs.Context.ResetMemfsContext before using memfs:// paths\")\n}","typeGuard":"func isUninitializedMemfsErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"memfs context not initialized\")\n}","tryCatchPattern":"p, err := vfs.Context.BuildVfsPath(\"memfs://test\")\nif err != nil {\n\tif isUninitializedMemfsErr(err) {\n\t\tvfs.Context.ResetMemfsContext(true)\n\t\tp, err = vfs.Context.BuildVfsPath(\"memfs://test\")\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n}","preventionTips":["Call vfs.Context.ResetMemfsContext(...) in test setup before any memfs:// usage","Treat memfs as test-only; use a real backend elsewhere","Avoid constructing VFSContext manually without initializing memfsContext"],"tags":["vfs","memfs","testing","initialization"],"backgroundTag":"uninitialized-memfs-context","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}