{"record":{"id":"3687d009f40f19b1","repo":"apache/beam","slug":"can-t-get-current-working-directory-w","errorCode":null,"errorMessage":"can't get current working directory: %w","messagePattern":"can't get current working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":304,"sourceCode":"\t}\n\n\tmanifest, err := os.ReadFile(tmpDir + \"/META-INF/MANIFEST.MF\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error readingf: %w\", err)\n\t}\n\n\t// trim the empty lines present at the end of MANIFEST.MF file.\n\tmanifestLines := strings.Split(string(manifest), \"\\n\")\n\tmanifestLines = manifestLines[:len(manifestLines)-2]\n\n\tclasspathString := fmt.Sprintf(\"%sClass-Path: %s\\n\", strings.Join(manifestLines, \"\\n\"), strings.Join(relClasspath, \" \"))\n\tif err = os.WriteFile(tmpDir+\"/META-INF/MANIFEST.MF\", []byte(classpathString), 0660); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error writing ta manifest file: %w\", err)\n\t}\n\n\tpath, err := os.Getwd()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't get current working directory: %w\", err)\n\t}\n\n\tif err = os.Chdir(tmpDir); err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't change to temp directory %s for creating JAR: %w\", tmpDir, err)\n\t}\n\n\ttmpJar := filepath.Join(cacheDir, \"tmp.jar\")\n\tif err = packJar(\".\", tmpJar); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error in packJar(): %w\", err)\n\t}\n\n\tif err = os.Chdir(path); err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't change to old working directory %s: %w\", path, err)\n\t}\n\n\treturn tmpJar, nil\n}\n","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L286-L322","documentation":"MakeJar calls os.Getwd to remember the current working directory before chdir-ing into tmpDir to pack the JAR. This error means the process working directory could not be determined (it was deleted or is unreadable), which is saved so it can be restored later.","triggerScenarios":"os.Getwd fails because the process's current working directory was removed (e.g. temp dir cleaned up while the process was running) or lacks read/execute permission.","commonSituations":"Started the expansion service from a directory that was subsequently deleted; running inside a container whose workdir was pruned; very long paths exceeding PATH_MAX.","solutions":["Restart the process from an existing, accessible directory (e.g. $HOME or the project root).","Ensure the launch directory is not deleted while the service runs.","Run as a user with read+execute permission on the current directory.","Verify the path length is within system limits."],"exampleFix":"// before: launching from a temp dir that gets cleaned\n$ cd /tmp/session-xyz && expansion-server\n// after\n$ cd ~/work && expansion-server","handlingStrategy":"validation","validationCode":"if wd, err := os.Getwd(); err != nil {\n    return fmt.Errorf(\"current working directory is gone: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"jar, err := expansionx.MakeJar(ctx, target, repo, version)\nif err != nil && strings.Contains(err.Error(), \"working directory\") {\n    os.Chdir(startDir) // restore a valid cwd before retrying\n    jar, err = expansionx.MakeJar(ctx, target, repo, version)\n}","preventionTips":["Launch services from stable directories (project root, $HOME), not ephemeral temp dirs.","Don't delete the launch directory while the process runs.","Use absolute paths for all inputs so cwd dependence is minimized."],"tags":["go","working-directory","os","filesystem"],"backgroundTag":"file-not-found","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"}