{"record":{"id":"5430be752ed34804","repo":"grafana/k6","slug":"open-failed-unable-to-verify-if-q-is-a-directo","errorCode":null,"errorMessage":"open() failed, unable to verify if %q is a directory; reason: %w","messagePattern":"open\\(\\) failed, unable to verify if %q is a directory; reason: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/fs/module.go","lineNumber":131,"sourceCode":"\t// how files are handled in different k6 contexts, so that we cater to\n\t// and intuitive user experience.\n\t//\n\t// See #2781 and #2674.\n\tpath = fsext.Abs(initEnv.CWD.Path, path)\n\n\tfs, ok := initEnv.FileSystems[\"file\"]\n\tif !ok {\n\t\treturn nil, errors.New(\"open() failed; reason: unable to access the file system\")\n\t}\n\n\tif exists, err := fsext.Exists(fs, path); err != nil {\n\t\treturn nil, fmt.Errorf(\"open() failed, unable to verify if %q exists; reason: %w\", path, err)\n\t} else if !exists {\n\t\treturn nil, newFsError(NotFoundError, fmt.Sprintf(\"no such file or directory %q\", path))\n\t}\n\n\tif isDir, err := fsext.IsDir(fs, path); err != nil {\n\t\treturn nil, fmt.Errorf(\"open() failed, unable to verify if %q is a directory; reason: %w\", path, err)\n\t} else if isDir {\n\t\treturn nil, newFsError(\n\t\t\tInvalidResourceError,\n\t\t\tfmt.Sprintf(\"cannot open %q: opening a directory is not supported\", path),\n\t\t)\n\t}\n\n\tdata, err := mi.cache.open(path, fs)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfile := &File{\n\t\tPath: path,\n\t\tReadSeekStater: &file{\n\t\t\tpath: path,\n\t\t\tdata: data,\n\t\t},","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/fs/module.go#L113-L149","documentation":"The experimental fs module's open() runs two probes before returning a file: Exists, then fsext.IsDir (opening a directory is rejected separately). If the IsDir probe itself errors, it is wrapped as 'open() failed, unable to verify if %q is a directory' (internal/js/modules/k6/experimental/fs/module.go:131). The file was confirmed to exist; the failure is the directory-check Stat call on the filesystem backend.","triggerScenarios":"fs.open(path) on a path whose Stat for the IsDir check fails - permission revoked between the two checks, corrupted archive entries with valid name but broken metadata, or an fsext/afero backend error.","commonSituations":"Same class as the existence-check failure: hardened CI environments with restrictive permissions, hand-edited k6 archives, and unusual mounts; the existence check passed moments earlier, so it is usually transient or metadata-specific.","solutions":["Re-check permissions on the file and parent directories","Re-run - a transient failure between two consecutive stat calls is the most likely cause","If reproducible from an archive, rebuild the archive from source files"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const f = open(path);\n} catch (e) {\n  if (/unable to verify if .* is a directory/.test(e.message)) {\n    // existence already passed; retry once, then check permissions/mount health\n    return open(path);\n  }\n  throw e;\n}","preventionTips":["Avoid mounts whose metadata operations are flaky","Re-run once on transient stat failures before debugging further","Keep the filesystem layer simple: local files or untouched archives"],"tags":["fs","k6","filesystem","permissions","experimental"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}