{"record":{"id":"8b9f691ccaddf271","repo":"apache/beam","slug":"error-creating-directory-s-in-extractjar-s-s-w","errorCode":null,"errorMessage":"error creating directory %s in extractJar(%s,%s): %w","messagePattern":"error creating directory (.+?) in extractJar\\((.+?),(.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":161,"sourceCode":"\tdestPath := filepath.Join(dest, filename)\n\tcleanDest := filepath.Clean(dest)\n\tcleanPath := filepath.Clean(destPath)\n\n\trel, err := filepath.Rel(cleanDest, cleanPath)\n\tif err != nil || strings.HasPrefix(rel, \"..\"+string(filepath.Separator)) || rel == \"..\" {\n\t\treturn \"\", fmt.Errorf(\"file path %q is outside destination directory %q\", filename, dest)\n\t}\n\treturn cleanPath, nil\n}\n\nfunc extractJar(source, dest string) error {\n\treader, err := zip.OpenReader(source)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error opening jar for extractJar(%s,%s): %w\", source, dest, err)\n\t}\n\n\tif err := os.MkdirAll(dest, 0700); err != nil {\n\t\treturn fmt.Errorf(\"error creating directory %s in extractJar(%s,%s): %w\", dest, source, dest, err)\n\t}\n\n\tfor _, file := range reader.File {\n\t\tfileName, err := validatePath(dest, file.Name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error validating file path (%s, %s): %w\", dest, file.Name, err)\n\t\t}\n\t\tif file.FileInfo().IsDir() {\n\t\t\tos.MkdirAll(fileName, 0700)\n\t\t\tcontinue\n\t\t}\n\n\t\tsf, err := file.Open()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error opening source file %s: %w\", file.Name, err)\n\t\t}\n\t\tdefer sf.Close()\n","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L143-L179","documentation":"extractJar creates the destination directory tree with os.MkdirAll(dest, 0700) before writing entries. This error wraps that failure, meaning the extraction destination could not be created — typically a permission problem on a parent directory, or a non-directory file already existing at the path.","triggerScenarios":"os.MkdirAll(dest, 0700) returns non-nil inside extractJar: parent directory not writable, dest exists as a regular file, or read-only filesystem.","commonSituations":"Running the Go worker in a container with a read-only root filesystem; dest collides with an existing file; extracting into a system directory as an unprivileged user.","solutions":["Ensure the parent of dest exists and is writable by the running user.","Remove or rename any regular file currently occupying dest.","Choose a destination on a writable volume (e.g. $TMPDIR).","Inspect the wrapped %w cause for the exact OS error (EACCES, EROFS, ENOTDIR)."],"exampleFix":"// before\nerr := expansionx.MakeJar(ctx, url, \"/opt/beam/jars\") // not writable\n// after\nerr := expansionx.MakeJar(ctx, url, filepath.Join(os.TempDir(), \"beam-jars\"))","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(dest); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dest)\n}\nif err := os.MkdirAll(dest, 0700); err != nil {\n    return fmt.Errorf(\"cannot pre-create extraction dir %s: %w\", dest, err)\n}","typeGuard":null,"tryCatchPattern":"err := expansionx.MakeJar(ctx, url, dest)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && (errors.Is(pe.Err, fs.ErrPermission) || errors.Is(pe.Err, syscall.EROFS)) {\n        dest = filepath.Join(os.TempDir(), \"beam-jars\")\n        return expansionx.MakeJar(ctx, url, dest)\n    }\n    return err\n}","preventionTips":["Choose extraction destinations on writable volumes, not read-only system paths.","Ensure the worker user owns or can write the parent directory.","Don't let a regular file occupy the destination path.","In containers, mount a writable volume for jar caching."],"tags":["go","filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}