{"record":{"id":"9b80be456b0fc0ed","repo":"golangci/golangci-lint","slug":"failed-to-get-shortest-rel-path-for-q-w","errorCode":null,"errorMessage":"failed to get shortest rel path for %q: %w","messagePattern":"failed to get shortest rel path for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/golinters/dupl/dupl.go","lineNumber":67,"sourceCode":"\t\tWithLoadMode(goanalysis.LoadModeSyntax)\n}\n\nfunc runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]*goanalysis.Issue, error) {\n\tissues, err := duplAPI.Run(internal.GetGoFileNames(pass), settings.Threshold)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(issues) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tres := make([]*goanalysis.Issue, 0, len(issues))\n\n\tfor _, i := range issues {\n\t\ttoFilename, err := fsutils.ShortestRelPath(i.To.Filename(), \"\")\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get shortest rel path for %q: %w\", i.To.Filename(), err)\n\t\t}\n\n\t\tdupl := fmt.Sprintf(\"%s:%d-%d\", toFilename, i.To.LineStart(), i.To.LineEnd())\n\t\ttext := fmt.Sprintf(\"%d-%d lines are duplicate of %s\",\n\t\t\ti.From.LineStart(), i.From.LineEnd(),\n\t\t\tinternal.FormatCode(dupl))\n\n\t\tres = append(res, goanalysis.NewIssue(&result.Issue{\n\t\t\tPos: token.Position{\n\t\t\t\tFilename: i.From.Filename(),\n\t\t\t\tLine:     i.From.LineStart(),\n\t\t\t},\n\t\t\tLineRange: &result.Range{\n\t\t\t\tFrom: i.From.LineStart(),\n\t\t\t\tTo:   i.From.LineEnd(),\n\t\t\t},\n\t\t\tText:       text,\n\t\t\tFromLinter: linterName,","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/golinters/dupl/dupl.go#L49-L85","documentation":"The dupl linter wrapper in golangci-lint reports each duplicate-code issue with a relative path for readability. Before formatting the issue text it calls fsutils.ShortestRelPath on the duplicated-to file; if that fails, runDupl aborts with 'failed to get shortest rel path for %q'.","triggerScenarios":"runDupl processed dupl issues and fsutils.ShortestRelPath(i.To.Filename(), \"\") returned an error — typically the reported file is not under the current working directory / module root, or path resolution failed (symlinks, unusual paths).","commonSituations":"Running golangci-lint from a directory outside the analyzed module, analyzed files behind symlinks or on different mount points, duplicate paths appearing via vendored or generated files outside the project root.","solutions":["Run golangci-lint from the repository/module root so relative path computation works","Exclude the offending path (vendored, symlinked, generated) via issues.exclude-* settings","Resolve symlinks so analyzed files live inside the project tree","Update golangci-lint if path handling (Windows/network paths) is the issue"],"exampleFix":"// run from module root instead of subdir\n// before: cd src && golangci-lint run\n// after\ncd /repo/root && golangci-lint run","handlingStrategy":"fallback","validationCode":"// Before running dupl-based tooling, ensure CWD is the module root:\nif _, err := os.Stat(\"go.mod\"); err != nil {\n    return fmt.Errorf(\"run from the module root so relative paths resolve: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"issues, err := runDupl(pass, issues)\nif err != nil && strings.Contains(err.Error(), \"shortest rel path\") {\n    // fall back to running from repo root or excluding the path\n    log.Warnf(\"dupl path resolution failed: %v\", err)\n    return nil, nil\n}","preventionTips":["Always invoke golangci-lint from the repository root (CI: working-directory: .)","Avoid symlinking source trees outside the module","Exclude vendored/generated paths via issues.exclude-* so paths stay in-tree"],"tags":["golangci-lint","dupl","path-resolution"],"backgroundTag":"relative-path-resolution-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}