@@ -9,7 +9,6 @@ package mvs
9
9
import (
10
10
"fmt"
11
11
"sort"
12
- "strings"
13
12
"sync"
14
13
"sync/atomic"
15
14
@@ -61,59 +60,6 @@ type Reqs interface {
61
60
Previous (m module.Version ) (module.Version , error )
62
61
}
63
62
64
- // BuildListError decorates an error that occurred gathering requirements
65
- // while constructing a build list. BuildListError prints the chain
66
- // of requirements to the module where the error occurred.
67
- type BuildListError struct {
68
- Err error
69
- stack []buildListErrorElem
70
- }
71
-
72
- type buildListErrorElem struct {
73
- m module.Version
74
-
75
- // nextReason is the reason this module depends on the next module in the
76
- // stack. Typically either "requires", or "upgraded to".
77
- nextReason string
78
- }
79
-
80
- // Module returns the module where the error occurred. If the module stack
81
- // is empty, this returns a zero value.
82
- func (e * BuildListError ) Module () module.Version {
83
- if len (e .stack ) == 0 {
84
- return module.Version {}
85
- }
86
- return e .stack [len (e .stack )- 1 ].m
87
- }
88
-
89
- func (e * BuildListError ) Error () string {
90
- b := & strings.Builder {}
91
- stack := e .stack
92
-
93
- // Don't print modules at the beginning of the chain without a
94
- // version. These always seem to be the main module or a
95
- // synthetic module ("target@").
96
- for len (stack ) > 0 && stack [0 ].m .Version == "" {
97
- stack = stack [1 :]
98
- }
99
-
100
- if len (stack ) == 0 {
101
- b .WriteString (e .Err .Error ())
102
- } else {
103
- for _ , elem := range stack [:len (stack )- 1 ] {
104
- fmt .Fprintf (b , "%s@%s %s\n \t " , elem .m .Path , elem .m .Version , elem .nextReason )
105
- }
106
- // Ensure that the final module path and version are included as part of the
107
- // error message.
108
- if _ , ok := e .Err .(* module.ModuleError ); ok {
109
- fmt .Fprintf (b , "%v" , e .Err )
110
- } else {
111
- fmt .Fprintf (b , "%v" , module .VersionError (stack [len (stack )- 1 ].m , e .Err ))
112
- }
113
- }
114
- return b .String ()
115
- }
116
-
117
63
// BuildList returns the build list for the target module.
118
64
//
119
65
// target is the root vertex of a module requirement graph. For cmd/go, this is
@@ -202,29 +148,30 @@ func buildList(target module.Version, reqs Reqs, upgrade func(module.Version) (m
202
148
q = q [1 :]
203
149
204
150
if node .err != nil {
205
- // Construct the stack reversed (from the error to the main module),
151
+ pathUpgrade := map [module.Version ]module.Version {}
152
+
153
+ // Construct the error path reversed (from the error to the main module),
206
154
// then reverse it to obtain the usual order (from the main module to
207
155
// the error).
208
- stack := []buildListErrorElem {{ m : node .m } }
156
+ errPath := []module. Version { node .m }
209
157
for n , prev := neededBy [node ], node ; n != nil ; n , prev = neededBy [n ], n {
210
- reason := "requires"
211
158
if n .upgrade == prev .m {
212
- reason = "updating to"
159
+ pathUpgrade [ n . m ] = prev . m
213
160
}
214
- stack = append (stack , buildListErrorElem { m : n .m , nextReason : reason } )
161
+ errPath = append (errPath , n .m )
215
162
}
216
- i , j := 0 , len (stack )- 1
163
+ i , j := 0 , len (errPath )- 1
217
164
for i < j {
218
- stack [i ], stack [j ] = stack [j ], stack [i ]
165
+ errPath [i ], errPath [j ] = errPath [j ], errPath [i ]
219
166
i ++
220
167
j --
221
168
}
222
169
223
- err := & BuildListError {
224
- Err : node .err ,
225
- stack : stack ,
170
+ isUpgrade := func (from , to module.Version ) bool {
171
+ return pathUpgrade [from ] == to
226
172
}
227
- return nil , err
173
+
174
+ return nil , NewBuildListError (node .err , errPath , isUpgrade )
228
175
}
229
176
230
177
neighbors := node .required
0 commit comments