{"record":{"id":"da9e5db1a72eedea","repo":"hyperledger/fabric","slug":"failed-to-get-working-directory","errorCode":null,"errorMessage":"failed to get working directory","messagePattern":"failed to get working directory","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/golang/platform.go","lineNumber":380,"sourceCode":"\t}, nil\n}\n\nfunc regularFileExists(path string) (bool, error) {\n\tfi, err := os.Stat(path)\n\tswitch {\n\tcase os.IsNotExist(err):\n\t\treturn false, nil\n\tcase err != nil:\n\t\treturn false, err\n\tdefault:\n\t\treturn fi.Mode().IsRegular(), nil\n\t}\n}\n\nfunc moduleInfo(path string) (*ModuleInfo, error) {\n\tentryWD, err := os.Getwd()\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to get working directory\")\n\t}\n\n\t// directory doesn't exist so unlikely to be a module\n\tif err := os.Chdir(path); err != nil {\n\t\treturn nil, nil\n\t}\n\tdefer func() {\n\t\tif err := os.Chdir(entryWD); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"failed to restore working directory: %s\", err))\n\t\t}\n\t}()\n\n\t// Using `go list -m -f '{{ if .Main }}{{.GoMod}}{{ end }}' all` may try to\n\t// generate a go.mod when a vendor tool is in use. To avoid that behavior\n\t// we use `go env GOMOD` followed by an existence check.\n\tcmd := exec.Command(\"go\", \"env\", \"GOMOD\")\n\tcmd.Env = os.Environ()\n\toutput, err := cmd.Output()","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/golang/platform.go#L362-L398","documentation":"moduleInfo saves the current working directory with os.Getwd() before chdir-ing into the chaincode path; if Getwd fails (e.g. the process's cwd was deleted), the wrapped 'failed to get working directory' error is returned.","triggerScenarios":"Calling moduleInfo (via DescribeCode or NormalizePath) when the current working directory of the process has been removed or is inaccessible, making os.Getwd fail.","commonSituations":"Long-running peer processes whose startup directory was deleted, containers with unusual cwd setups, permission changes on ancestor directories.","solutions":["Restart the peer/process from an existing working directory.","Ensure the process's cwd exists and is accessible before invoking chaincode packaging.","Avoid deleting directories the peer process was started from."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := os.Getwd(); err != nil {\n\treturn fmt.Errorf(\"process cwd unusable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := golang.DescribeCode(path); err != nil {\n\tif strings.Contains(err.Error(), \"failed to get working directory\") {\n\t\t// restart peer from an existing directory\n\t}\n}","preventionTips":["Start the peer from a stable, existing directory","Never delete the directory a long-running process was launched from","Monitor container mounts for the process cwd"],"tags":["filesystem","working-directory","hyperledger-fabric"],"backgroundTag":"working-directory-unavailable","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}