Skip to content

Commit

Permalink
modfile: improve error message for replace with '@' in path
Browse files Browse the repository at this point in the history
Replacement module must match format 'path version', not 'path@version'. In this case, return a more explicit error message.

Fixes golang/go#35041.

Change-Id: I4d1437fc7499abca4af426afb535bfdd0f5b254e
Reviewed-on: https://go-review.googlesource.com/c/mod/+/408014
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
hopehook authored and gopherbot committed Aug 10, 2022
1 parent 86c51ed commit 046e8b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ func parseReplace(filename string, line *Line, verb string, args []string, fix V
nv := ""
if len(args) == arrow+2 {
if !IsDirectoryPath(ns) {
if strings.Contains(ns, "@") {
return nil, errorf("replacement module must match format 'path version', not 'path@version'")
}
return nil, errorf("replacement module without version must be directory path (rooted or starting with ./ or ../)")
}
if filepath.Separator == '/' && strings.Contains(ns, `\`) {
Expand Down
12 changes: 12 additions & 0 deletions modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,18 @@ var fixVersionTests = []struct {
want: `replace example.com/m v1.0.0 => example.com/m v1.1.0`,
fix: fixV,
},
{
desc: `replace_version_in_path`,
in: `replace example.com/m@v1.0.0 => example.com/m@v1.1.0`,
wantErr: `replacement module must match format 'path version', not 'path@version'`,
fix: fixV,
},
{
desc: `replace_version_in_later_path`,
in: `replace example.com/m => example.com/m@v1.1.0`,
wantErr: `replacement module must match format 'path version', not 'path@version'`,
fix: fixV,
},
{
desc: `exclude`,
in: `exclude example.com/m 1.0.0`,
Expand Down

0 comments on commit 046e8b3

Please sign in to comment.