diff --git a/container/Container.go b/container/Container.go index af0e0d5..3dfbd1c 100644 --- a/container/Container.go +++ b/container/Container.go @@ -1,8 +1,10 @@ package container import ( + "errors" + cconfig "github.com/pip-services3-go/pip-services3-commons-go/config" - "github.com/pip-services3-go/pip-services3-commons-go/errors" + cerr "github.com/pip-services3-go/pip-services3-commons-go/errors" crefer "github.com/pip-services3-go/pip-services3-commons-go/refer" cbuild "github.com/pip-services3-go/pip-services3-components-go/build" "github.com/pip-services3-go/pip-services3-components-go/info" @@ -208,14 +210,18 @@ func (c *Container) Open(correlationId string) error { var err error if c.references != nil { - return errors.NewInvalidStateError( + return cerr.NewInvalidStateError( correlationId, "ALREADY_OPENED", "Container was already opened", ) } defer func() { if r := recover(); r != nil { - err, _ = r.(error) + err, ok := r.(error) + if !ok { + msg, _ := r.(string) + err = errors.New(msg) + } c.logger.Error(correlationId, err, "Failed to start container") c.Close(correlationId) } @@ -272,7 +278,11 @@ func (c *Container) Close(correlationId string) error { defer func() { if r := recover(); r != nil { - err, _ = r.(error) + err, ok := r.(error) + if !ok { + msg, _ := r.(string) + err = errors.New(msg) + } c.logger.Error(correlationId, err, "Failed to stop container") } }() diff --git a/container/ProcessContainer.go b/container/ProcessContainer.go index df4ec76..c9b39f6 100644 --- a/container/ProcessContainer.go +++ b/container/ProcessContainer.go @@ -1,6 +1,7 @@ package container import ( + "errors" "fmt" "os" "os/signal" @@ -25,7 +26,7 @@ Container Example container = NewEmptyProcessContainer(); container.Container.AddFactory(NewMyComponentFactory()); - + container.Run(process.args); */ type ProcessContainer struct { @@ -152,7 +153,11 @@ func (c *ProcessContainer) printHelp() { func (c *ProcessContainer) captureErrors(correlationId string) { if r := recover(); r != nil { - err, _ := r.(error) + err, ok := r.(error) + if !ok { + msg, _ := r.(string) + err = errors.New(msg) + } c.Logger().Fatal(correlationId, err, "Process is terminated") os.Exit(1) } diff --git a/examples/DummyController.go b/examples/DummyController.go index 7804fd9..2d40cee 100644 --- a/examples/DummyController.go +++ b/examples/DummyController.go @@ -8,15 +8,15 @@ import ( ) type DummyController struct { - timer *run.FixedRateTimer - logger *log.CompositeLogger + timer *run.FixedRateTimer + logger *log.CompositeLogger message string counter int } func NewDummyController() *DummyController { - c := &DummyController { - logger: log.NewCompositeLogger(), + c := &DummyController{ + logger: log.NewCompositeLogger(), message: "Hello World!", counter: 0, } @@ -69,4 +69,4 @@ func (c *DummyController) Close(correlationId string) error { func (c *DummyController) Notify(correlationId string, args *run.Parameters) { c.logger.Info(correlationId, "%d - %s", c.counter, c.message) c.counter++ -} \ No newline at end of file +}