Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 2058950

Browse files
committed
internal/gps: extract ValidateParams
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 3a28237 commit 2058950

File tree

4 files changed

+20
-50
lines changed

4 files changed

+20
-50
lines changed

cmd/dep/ensure.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,20 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
142142
}
143143
}
144144

145-
solver, err := gps.Prepare(params, sm)
145+
err = gps.ValidateParams(params, sm)
146146
if err != nil {
147-
if deduceErrs, ok := err.(gps.DeductionFailureErrs); ok {
147+
if deduceErrs, ok := err.(gps.DeductionErrs); ok {
148148
ctx.Loggers.Err.Println("The following errors occurred while deducing packages:")
149149
for ip, dErr := range deduceErrs {
150150
ctx.Loggers.Err.Printf(" * \"%s\": %s", ip, dErr)
151151
}
152152
ctx.Loggers.Err.Println()
153153
}
154+
return errors.Wrap(err, "validateParams")
155+
}
156+
157+
solver, err := gps.Prepare(params, sm)
158+
if err != nil {
154159
return errors.Wrap(err, "ensure Prepare")
155160
}
156161

internal/gps/hash_test.go

-35
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ func TestHashInputs(t *testing.T) {
2727

2828
s, err := Prepare(params, newdepspecSM(fix.ds, nil))
2929
if err != nil {
30-
if deduceErrs, ok := err.(DeductionFailureErrs); ok {
31-
t.Error("The following errors occurred while deducing packages:")
32-
for ip, dErr := range deduceErrs {
33-
t.Errorf(" * \"%s\": %s", ip, dErr)
34-
}
35-
t.Error()
36-
}
3730
t.Fatalf("Unexpected error while prepping solver: %s", err)
3831
}
3932

@@ -87,13 +80,6 @@ func TestHashInputsReqsIgs(t *testing.T) {
8780

8881
s, err := Prepare(params, newdepspecSM(fix.ds, nil))
8982
if err != nil {
90-
if deduceErrs, ok := err.(DeductionFailureErrs); ok {
91-
t.Error("The following errors occurred while deducing packages:")
92-
for ip, dErr := range deduceErrs {
93-
t.Errorf(" * \"%s\": %s", ip, dErr)
94-
}
95-
t.Error()
96-
}
9783
t.Fatalf("Unexpected error while prepping solver: %s", err)
9884
}
9985

@@ -136,13 +122,6 @@ func TestHashInputsReqsIgs(t *testing.T) {
136122

137123
s, err = Prepare(params, newdepspecSM(fix.ds, nil))
138124
if err != nil {
139-
if deduceErrs, ok := err.(DeductionFailureErrs); ok {
140-
t.Error("The following errors occurred while deducing packages:")
141-
for ip, dErr := range deduceErrs {
142-
t.Errorf(" * \"%s\": %s", ip, dErr)
143-
}
144-
t.Error()
145-
}
146125
t.Fatalf("Unexpected error while prepping solver: %s", err)
147126
}
148127

@@ -183,13 +162,6 @@ func TestHashInputsReqsIgs(t *testing.T) {
183162

184163
s, err = Prepare(params, newdepspecSM(fix.ds, nil))
185164
if err != nil {
186-
if deduceErrs, ok := err.(DeductionFailureErrs); ok {
187-
t.Error("The following errors occurred while deducing packages:")
188-
for ip, dErr := range deduceErrs {
189-
t.Errorf(" * \"%s\": %s", ip, dErr)
190-
}
191-
t.Error()
192-
}
193165
t.Fatalf("Unexpected error while prepping solver: %s", err)
194166
}
195167

@@ -556,13 +528,6 @@ func TestHashInputsOverrides(t *testing.T) {
556528

557529
s, err := Prepare(params, newdepspecSM(basefix.ds, nil))
558530
if err != nil {
559-
if deduceErrs, ok := err.(DeductionFailureErrs); ok {
560-
t.Error("The following errors occurred while deducing packages:")
561-
for ip, dErr := range deduceErrs {
562-
t.Errorf(" * \"%s\": %s", ip, dErr)
563-
}
564-
t.Error()
565-
}
566531
t.Errorf("(fix: %q) Unexpected error while prepping solver: %s", fix.name, err)
567532
continue
568533
}

internal/gps/solve_failures.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ func (e badOptsFailure) Error() string {
239239
return string(e)
240240
}
241241

242-
// DeductionFailureErrs maps package import path to errors occurring during deduction.
243-
type DeductionFailureErrs map[string]error
242+
// DeductionErrs maps package import path to errors occurring during deduction.
243+
type DeductionErrs map[string]error
244244

245-
func (e DeductionFailureErrs) Error() string {
246-
return "could not deduce packages to ensure constraints are solvable"
245+
func (e DeductionErrs) Error() string {
246+
return "could not deduce external imports' project roots"
247247
}
248248

249249
type sourceMismatchFailure struct {

internal/gps/solver.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,6 @@ func Prepare(params SolveParameters, sm SourceManager) (Solver, error) {
284284
params.stdLibFn = paths.IsStandardImportPath
285285
}
286286

287-
// Validate the solver parameters
288-
if err := validateParams(sm, rd, params.stdLibFn); err != nil {
289-
return nil, err
290-
}
291-
292287
s := &solver{
293288
tl: params.TraceLogger,
294289
stdLibFn: params.stdLibFn,
@@ -538,13 +533,18 @@ func (s *solver) solve() (map[atom]map[string]struct{}, error) {
538533
return projs, nil
539534
}
540535

541-
// validateParams validates the solver parameters to ensure solving can be completed.
542-
func validateParams(sm SourceManager, rd rootdata, stdLibFn func(string) bool) error {
536+
// ValidateParams validates the solver parameters to ensure solving can be completed.
537+
func ValidateParams(params SolveParameters, sm SourceManager) error {
543538
// Ensure that all packages are deducible without issues.
544539
var deducePkgsGroup sync.WaitGroup
545-
deductionErrs := make(DeductionFailureErrs)
540+
deductionErrs := make(DeductionErrs)
546541
var errsMut sync.Mutex
547542

543+
rd, err := params.toRootdata()
544+
if err != nil {
545+
return err
546+
}
547+
548548
deducePkg := func(ip string, sm SourceManager) {
549549
_, err := sm.DeduceProjectRoot(ip)
550550
if err != nil {
@@ -555,7 +555,7 @@ func validateParams(sm SourceManager, rd rootdata, stdLibFn func(string) bool) e
555555
deducePkgsGroup.Done()
556556
}
557557

558-
for _, ip := range rd.externalImportList(stdLibFn) {
558+
for _, ip := range rd.externalImportList(paths.IsStandardImportPath) {
559559
deducePkgsGroup.Add(1)
560560
go deducePkg(ip, sm)
561561
}

0 commit comments

Comments
 (0)