{"record":{"id":"3fc66fd023704e8f","repo":"apache/beam","slug":"can-t-change-to-old-working-directory-s-w","errorCode":null,"errorMessage":"can't change to old working directory %s: %w","messagePattern":"can't change to old working directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":317,"sourceCode":"\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\n// GetBeamJar checks a temporary directory for the desired Beam JAR, downloads the\n// appropriate JAR from Maven if not present, then returns the file path to the\n// JAR.\nfunc GetBeamJar(gradleTarget, version string) (string, error) {\n\treturn defaultJarGetter.getJar(gradleTarget, version)\n}\n\nfunc (j *jarGetter) getRepositoryURL() string {\n\treturn string(j.repository)\n}\n\nfunc (j *jarGetter) setRepositoryURL(repoURL string) error {\n\tif !strings.HasPrefix(repoURL, \"http\") {","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L299-L335","documentation":"MakeJar changes the working directory into tmpDir for packing and must restore the original directory afterwards; failure to os.Chdir back to the saved path is wrapped as \"can't change to old working directory\". The JAR itself is already packed, but the process is left in an unexpected directory.","triggerScenarios":"os.Chdir(path) fails because the original working directory was deleted or made inaccessible while the function ran (common when started from a directory later removed), or permission changes occurred.","commonSituations":"Home/project directory removed during a long expansion-service startup; container working volume unmounted; user permissions revoked mid-run.","solutions":["Re-run after ensuring the launch directory still exists.","If only the directory restoration failed, the returned tmpJar may still be valid — check the caller's handling.","Keep the launch directory stable for the process lifetime.","Prefer library-side refactoring to avoid chdir (e.g. packJar with an explicit root) instead of restoring cwd."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"jar, err := expansionx.MakeJar(ctx, target, repo, version)\nif err != nil && strings.Contains(err.Error(), \"old working directory\") {\n    // JAR may already be packed; log and continue in a valid cwd\n    log.Printf(\"warning: cwd restore failed: %v\", err)\n    os.Chdir(\"/\")\n}","preventionTips":["Keep the launch directory alive for the process lifetime.","Start the service from a stable, always-present directory.","Treat this as a warning: the produced JAR is usually still usable."],"tags":["go","chdir","working-directory","filesystem"],"backgroundTag":"directory-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"}