Skip to content

Commit

Permalink
Fix close method in RunReferencesDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
levichevdmitry committed Apr 2, 2021
1 parent a74c271 commit 07daa7d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> IoC container for Golang Changelog

## <a name="1.0.4"></a> 1.0.4 (2021-04-02)

### Bug Fixes
* **container** Fix close method in RunReferencesDecorator. Now all components are closing when error happened on openinig references in Container

## <a name="1.0.3"></a> 1.0.3 (2021-03-23)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pip-services3-container-go",
"registry": "github.com/pip-services3-go",
"version": "3.0.0",
"version": "1.0.4",
"build": 0
}
11 changes: 6 additions & 5 deletions container/Container.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func (c *Container) IsOpen() bool {
// - correlationId string
// transaction id to trace execution through call chain.
// Returns error
func (c *Container) Open(correlationId string) error {
var err error
func (c *Container) Open(correlationId string) (err error) {
//var err error

if c.references != nil {
return cerr.NewInvalidStateError(
Expand All @@ -217,12 +217,13 @@ func (c *Container) Open(correlationId string) error {

defer func() {
if r := recover(); r != nil {
err, ok := r.(error)
recoverErr, ok := r.(error)
if !ok {
msg, _ := r.(string)
err = errors.New(msg)
recoverErr = errors.New(msg)
}
c.logger.Error(correlationId, err, "Failed to start container")
err = recoverErr
c.logger.Error(correlationId, recoverErr, "Failed to start container")
c.Close(correlationId)
}
}()
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"os"

"github.com/pip-services3-go/pip-services3-container-go/examples"
)

func main() {
process := examples.NewDummyProcess()
process.Run(os.Args)
}
}
14 changes: 7 additions & 7 deletions refer/RunReferencesDecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (c *RunReferencesDecorator) Open(correlationId string) error {
// transaction id to trace execution through call chain.
// Returns error
func (c *RunReferencesDecorator) Close(correlationId string) error {
if c.opened {
components := c.GetAll()
err := run.Closer.Close(correlationId, components)
c.opened = false
return err
}
return nil
//if c.opened {
components := c.GetAll()
err := run.Closer.Close(correlationId, components)
c.opened = false
return err
// }
// return nil
}

// Puts a new reference into this reference map.
Expand Down

0 comments on commit 07daa7d

Please sign in to comment.