apache/beam · error
can't get current working directory
Error message
can't get current working directory: %w
What it means
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.
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.
Example fix
// before: launching from a temp dir that gets cleaned $ cd /tmp/session-xyz && expansion-server // after $ cd ~/work && expansion-server
Defensive patterns
Strategy: validation
Validate before calling
if wd, err := os.Getwd(); err != nil {
return fmt.Errorf("current working directory is gone: %w", err)
} Try / catch
jar, err := expansionx.MakeJar(ctx, target, repo, version)
if err != nil && strings.Contains(err.Error(), "working directory") {
os.Chdir(startDir) // restore a valid cwd before retrying
jar, err = expansionx.MakeJar(ctx, target, repo, version)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- can't change to old working directory
- can't change to temp directory
- chunk write failed
- error accesing path
- error creating directory
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/3687d009f40f19b1.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:304
}
manifest, err := os.ReadFile(tmpDir + "/META-INF/MANIFEST.MF")
if err != nil {
return "", fmt.Errorf("error readingf: %w", err)
}
// trim the empty lines present at the end of MANIFEST.MF file.
manifestLines := strings.Split(string(manifest), "\n")
manifestLines = manifestLines[:len(manifestLines)-2]
classpathString := fmt.Sprintf("%sClass-Path: %s\n", strings.Join(manifestLines, "\n"), strings.Join(relClasspath, " "))
if err = os.WriteFile(tmpDir+"/META-INF/MANIFEST.MF", []byte(classpathString), 0660); err != nil {
return "", fmt.Errorf("error writing ta manifest file: %w", err)
}
path, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("can't get current working directory: %w", err)
}
if err = os.Chdir(tmpDir); err != nil {
return "", fmt.Errorf("can't change to temp directory %s for creating JAR: %w", tmpDir, err)
}
tmpJar := filepath.Join(cacheDir, "tmp.jar")
if err = packJar(".", tmpJar); err != nil {
return "", fmt.Errorf("error in packJar(): %w", err)
}
if err = os.Chdir(path); err != nil {
return "", fmt.Errorf("can't change to old working directory %s: %w", path, err)
}
return tmpJar, nil
}
View on GitHub (pinned to 12126d8942)