{"record":{"id":"8f809034307da9a8","repo":"hyperledger/fabric","slug":"failed-to-calculate-relative-path-for-s","errorCode":null,"errorMessage":"failed to calculate relative path for %s","messagePattern":"failed to calculate relative path for (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/golang/platform.go","lineNumber":492,"sourceCode":"\t\t\t}\n\n\t\t\t// include everything except hidden dirs when we're not vendoring\n\t\t\tif cd.Module && !strings.HasPrefix(info.Name(), \".\") {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\t// Do not import any other directories into chaincode code package\n\t\t\treturn filepath.SkipDir\n\t\t}\n\n\t\trelativeRoot := cd.Source\n\t\tif cd.isMetadata(path) {\n\t\t\trelativeRoot = cd.MetadataRoot\n\t\t}\n\n\t\tname, err := filepath.Rel(relativeRoot, path)\n\t\tif err != nil {\n\t\t\treturn errors.Wrapf(err, \"failed to calculate relative path for %s\", path)\n\t\t}\n\n\t\tswitch {\n\t\tcase cd.isMetadata(path):\n\t\t\t// Skip hidden files in metadata\n\t\t\tif strings.HasPrefix(info.Name(), \".\") {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tname = filepath.Join(\"META-INF\", name)\n\t\t\terr := validateMetadata(name, path)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tcase cd.Module:\n\t\t\tname = filepath.Join(\"src\", name)\n\t\tdefault:\n\t\t\t// skip top level go.mod and go.sum when not in module mode\n\t\t\tif name == \"go.mod\" || name == \"go.sum\" {","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/golang/platform.go#L474-L510","documentation":"findSource computes each discovered file's archive name as a path relative to the source or metadata root; if filepath.Rel cannot make the path relative to that root, the error is wrapped with 'failed to calculate relative path for %s'.","triggerScenarios":"A walked file path that is not underneath cd.Source or cd.MetadataRoot (e.g. after symlink resolution or mixed absolute/relative roots), causing filepath.Rel to fail.","commonSituations":"Symlinked source directories resolving outside the declared chaincode path, inconsistent path separators, roots computed via different absolutization than the walked paths.","solutions":["Ensure the chaincode path and all sources are canonical absolute paths with no symlinks escaping the root.","Keep sources physically inside the chaincode directory tree.","Compare the logged %s path against the roots to find the escaping path and remove/relocate it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"root, _ := filepath.Abs(ccPath)\nfilepath.Walk(root, func(p string, info os.FileInfo, err error) error {\n\tif info != nil && info.Mode()&os.ModeSymlink != 0 {\n\t\treturn fmt.Errorf(\"symlink escapes root: %s\", p)\n\t}\n\treturn nil\n})","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tif strings.Contains(err.Error(), \"failed to calculate relative path\") {\n\t\t// locate path from the message; remove escaping symlink or relocate file\n\t}\n}","preventionTips":["Use real directories, not symlinked source roots","Ensure canonical absolute paths for the chaincode dir","Audit source trees for symlinks pointing outside the package"],"tags":["chaincode","filesystem","path","hyperledger-fabric"],"backgroundTag":"relative-path-computation-failed","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"}