Skip to content

Commit 9036807

Browse files
author
Mrunal Patel
committed
Merge pull request docker-archive#424 from dqminh/fix-generic-error
Fix panic when genericError constructor gets nil error
2 parents 3ca0e1f + e22b589 commit 9036807

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

container_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (c *linuxContainer) Destroy() error {
212212
return err
213213
}
214214
if status != Destroyed {
215-
return newGenericError(nil, ContainerNotStopped)
215+
return newGenericError(fmt.Errorf("container is not destroyed"), ContainerNotStopped)
216216
}
217217
if !c.config.Namespaces.Contains(configs.NEWPID) {
218218
if err := killCgroupProcesses(c.cgroupManager); err != nil {

generic_error.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,32 @@ func newGenericError(err error, c ErrorCode) Error {
2525
if le, ok := err.(Error); ok {
2626
return le
2727
}
28-
return &genericError{
28+
gerr := &genericError{
2929
Timestamp: time.Now(),
3030
Err: err,
31-
Message: err.Error(),
3231
ECode: c,
3332
Stack: stacktrace.Capture(1),
3433
}
34+
if err != nil {
35+
gerr.Message = err.Error()
36+
}
37+
return gerr
3538
}
3639

3740
func newSystemError(err error) Error {
3841
if le, ok := err.(Error); ok {
3942
return le
4043
}
41-
return &genericError{
44+
gerr := &genericError{
4245
Timestamp: time.Now(),
4346
Err: err,
4447
ECode: SystemError,
45-
Message: err.Error(),
4648
Stack: stacktrace.Capture(1),
4749
}
50+
if err != nil {
51+
gerr.Message = err.Error()
52+
}
53+
return gerr
4854
}
4955

5056
type genericError struct {

process.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libcontainer
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67
)
@@ -46,23 +47,23 @@ type Process struct {
4647
// Wait releases any resources associated with the Process
4748
func (p Process) Wait() (*os.ProcessState, error) {
4849
if p.ops == nil {
49-
return nil, newGenericError(nil, ProcessNotExecuted)
50+
return nil, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
5051
}
5152
return p.ops.wait()
5253
}
5354

5455
// Pid returns the process ID
5556
func (p Process) Pid() (int, error) {
5657
if p.ops == nil {
57-
return -1, newGenericError(nil, ProcessNotExecuted)
58+
return -1, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
5859
}
5960
return p.ops.pid(), nil
6061
}
6162

6263
// Signal sends a signal to the Process.
6364
func (p Process) Signal(sig os.Signal) error {
6465
if p.ops == nil {
65-
return newGenericError(nil, ProcessNotExecuted)
66+
return newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted)
6667
}
6768
return p.ops.signal(sig)
6869
}

0 commit comments

Comments
 (0)