@@ -160,7 +160,7 @@ func (r *Runc) Create(context context.Context, id, bundle string, opts *CreateOp
160
160
}
161
161
status , err := Monitor .Wait (cmd , ec )
162
162
if err == nil && status != 0 {
163
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
163
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
164
164
}
165
165
return err
166
166
}
@@ -194,7 +194,7 @@ func (o *ExecOpts) args() (out []string, err error) {
194
194
return out , nil
195
195
}
196
196
197
- // Exec executres and additional process inside the container based on a full
197
+ // Exec executes an additional process inside the container based on a full
198
198
// OCI Process specification
199
199
func (r * Runc ) Exec (context context.Context , id string , spec specs.Process , opts * ExecOpts ) error {
200
200
f , err := ioutil .TempFile (os .Getenv ("XDG_RUNTIME_DIR" ), "runc-process" )
@@ -223,7 +223,7 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
223
223
data , err := cmdOutput (cmd , true )
224
224
defer putBuf (data )
225
225
if err != nil {
226
- return fmt .Errorf ("%s : %s" , err , data .String ())
226
+ return fmt .Errorf ("%w : %s" , err , data .String ())
227
227
}
228
228
return nil
229
229
}
@@ -240,7 +240,7 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
240
240
}
241
241
status , err := Monitor .Wait (cmd , ec )
242
242
if err == nil && status != 0 {
243
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
243
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
244
244
}
245
245
return err
246
246
}
@@ -266,7 +266,7 @@ func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts)
266
266
}
267
267
status , err := Monitor .Wait (cmd , ec )
268
268
if err == nil && status != 0 {
269
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
269
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
270
270
}
271
271
return status , err
272
272
}
@@ -584,7 +584,7 @@ func (r *Runc) Restore(context context.Context, id, bundle string, opts *Restore
584
584
}
585
585
status , err := Monitor .Wait (cmd , ec )
586
586
if err == nil && status != 0 {
587
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
587
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
588
588
}
589
589
return status , err
590
590
}
@@ -681,7 +681,7 @@ func (r *Runc) runOrError(cmd *exec.Cmd) error {
681
681
}
682
682
status , err := Monitor .Wait (cmd , ec )
683
683
if err == nil && status != 0 {
684
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
684
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
685
685
}
686
686
return err
687
687
}
@@ -709,8 +709,16 @@ func cmdOutput(cmd *exec.Cmd, combined bool) (*bytes.Buffer, error) {
709
709
710
710
status , err := Monitor .Wait (cmd , ec )
711
711
if err == nil && status != 0 {
712
- err = fmt .Errorf ("%s did not terminate successfully" , cmd .Args [0 ])
712
+ err = fmt .Errorf ("%s did not terminate successfully: %w " , cmd .Args [0 ], & ExitError { status } )
713
713
}
714
714
715
715
return b , err
716
716
}
717
+
718
+ type ExitError struct {
719
+ Status int
720
+ }
721
+
722
+ func (e * ExitError ) Error () string {
723
+ return fmt .Sprintf ("exit status %d" , e .Status )
724
+ }
0 commit comments