@@ -85,19 +85,19 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
8585 root = filepath .Join (ctx .WorkingDir , args [0 ])
8686 }
8787 if err := os .MkdirAll (root , os .FileMode (0777 )); err != nil {
88- return errors .Wrapf (err , "unable to create directory %s" , root )
88+ return errors .Wrapf (err , "init failed: unable to create a directory at %s" , root )
8989 }
9090 }
9191
9292 var err error
9393 p := new (dep.Project )
9494 if err = p .SetRoot (root ); err != nil {
95- return errors .Wrap (err , "NewProject" )
95+ return errors .Wrapf (err , "init failed: unable to set the root project to %s" , root )
9696 }
9797
9898 ctx .GOPATH , err = ctx .DetectProjectGOPATH (p )
9999 if err != nil {
100- return errors .Wrapf (err , "ctx.DetectProjectGOPATH " )
100+ return errors .Wrapf (err , "init failed: unable to detect the containing GOPATH " )
101101 }
102102
103103 mf := filepath .Join (root , dep .ManifestName )
@@ -106,30 +106,30 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
106106
107107 mok , err := fs .IsRegular (mf )
108108 if err != nil {
109- return err
109+ return errors . Wrapf ( err , "init failed: unable to check for an existing manifest at %s" , mf )
110110 }
111111 if mok {
112- return errors .Errorf ("manifest already exists: %s" , mf )
112+ return errors .Errorf ("init aborted: manifest already exists at %s" , mf )
113113 }
114114 // Manifest file does not exist.
115115
116116 lok , err := fs .IsRegular (lf )
117117 if err != nil {
118- return err
118+ return errors . Wrapf ( err , "init failed: unable to check for an existing lock at %s" , lf )
119119 }
120120 if lok {
121- return errors .Errorf ("invalid state: manifest %q does not exist, but lock %q does" , mf , lf )
121+ return errors .Errorf ("invalid aborted: lock already exists at %s" , lf )
122122 }
123123
124124 ip , err := ctx .ImportForAbs (root )
125125 if err != nil {
126- return errors .Wrap (err , "root project import" )
126+ return errors .Wrapf (err , "init failed: unable to determine the import path for the root project %s" , root )
127127 }
128128 p .ImportRoot = gps .ProjectRoot (ip )
129129
130130 sm , err := ctx .SourceManager ()
131131 if err != nil {
132- return errors .Wrap (err , "getSourceManager " )
132+ return errors .Wrap (err , "init failed: unable to create a source manager " )
133133 }
134134 sm .UseDefaultSignalHandling ()
135135 defer sm .Release ()
@@ -139,7 +139,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
139139 }
140140 pkgT , directDeps , err := getDirectDependencies (sm , p )
141141 if err != nil {
142- return err
142+ return errors . Wrap ( err , "init failed: unable to determine direct dependencies" )
143143 }
144144 if ctx .Verbose {
145145 ctx .Out .Printf ("Checked %d directories for packages.\n Found %d direct dependencies.\n " , len (pkgT .Packages ), len (directDeps ))
@@ -149,14 +149,14 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
149149 rootAnalyzer := newRootAnalyzer (cmd .skipTools , ctx , directDeps , sm )
150150 p .Manifest , p .Lock , err = rootAnalyzer .InitializeRootManifestAndLock (root , p .ImportRoot )
151151 if err != nil {
152- return err
152+ return errors . Wrap ( err , "init failed: unable to prepare an initial manifest and lock for the solver" )
153153 }
154154
155155 if cmd .gopath {
156156 gs := newGopathScanner (ctx , directDeps , sm )
157157 err = gs .InitializeRootManifestAndLock (p .Manifest , p .Lock )
158158 if err != nil {
159- return err
159+ return errors . Wrap ( err , "init failed: unable to scan the GOPATH for dependencies" )
160160 }
161161 }
162162
@@ -176,17 +176,18 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
176176 }
177177
178178 if err := ctx .ValidateParams (sm , params ); err != nil {
179- return err
179+ return errors . Wrapf ( err , "init failed: validation of solve parameters failed" )
180180 }
181181
182182 s , err := gps .Prepare (params , sm )
183183 if err != nil {
184- return errors .Wrap (err , "prepare solver" )
184+ return errors .Wrap (err , "init failed: unable to prepare the solver" )
185185 }
186186
187187 soln , err := s .Solve (context .TODO ())
188188 if err != nil {
189- return handleAllTheFailuresOfTheWorld (err )
189+ err = handleAllTheFailuresOfTheWorld (err )
190+ return errors .Wrap (err , "init failed: unable to solve the dependency graph" )
190191 }
191192 p .Lock = dep .LockFromSolution (soln )
192193
@@ -196,31 +197,31 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
196197 // to generate the final lock memo.
197198 s , err = gps .Prepare (params , sm )
198199 if err != nil {
199- return errors .Wrap (err , "prepare solver " )
200+ return errors .Wrap (err , "init failed: unable to recalculate the lock digest " )
200201 }
201202
202203 p .Lock .SolveMeta .InputsDigest = s .HashInputs ()
203204
204205 // Pass timestamp (yyyyMMddHHmmss format) as suffix to backup name.
205206 vendorbak , err := dep .BackupVendor (vpath , time .Now ().Format ("20060102150405" ))
206207 if err != nil {
207- return err
208+ return errors . Wrap ( err , "init failed: first backup vendor/, delete it, and then retry the previous command: failed to backup existing vendor directory" )
208209 }
209210 if vendorbak != "" {
210211 ctx .Err .Printf ("Old vendor backed up to %v" , vendorbak )
211212 }
212213
213214 sw , err := dep .NewSafeWriter (p .Manifest , nil , p .Lock , dep .VendorAlways )
214215 if err != nil {
215- return err
216+ return errors . Wrap ( err , "init failed: unable to create a SafeWriter" )
216217 }
217218
218219 logger := ctx .Err
219220 if ! ctx .Verbose {
220221 logger = log .New (ioutil .Discard , "" , 0 )
221222 }
222223 if err := sw .Write (root , sm , ! cmd .noExamples , logger ); err != nil {
223- return errors .Wrap (err , "safe write of manifest and lock " )
224+ return errors .Wrap (err , "init failed: unable to write the manifest, lock and vendor directory to disk " )
224225 }
225226
226227 return nil
0 commit comments