@@ -2,6 +2,7 @@ package mongo
22
33import (
44 "context"
5+ "github.com/xgodev/boost/model/errors"
56 "github.com/xgodev/boost/wrapper/log"
67 "strings"
78
@@ -36,7 +37,8 @@ func NewConn(ctx context.Context, plugins ...Plugin) (*Conn, error) {
3637
3738 o , err := NewOptions ()
3839 if err != nil {
39- logger .Fatalf (err .Error ())
40+ logger .Errorf ("Failed to get default options: %v" , err )
41+ return nil , errors .NewInternal (err , "failed to get default options" )
4042 }
4143
4244 return NewConnWithOptions (ctx , o , plugins ... )
@@ -71,12 +73,14 @@ func NewConnWithOptions(ctx context.Context, o *Options, plugins ...Plugin) (con
7173
7274 co , err := clientOptions (ctx , o )
7375 if err != nil {
74- logger .Fatalf (err .Error ())
76+ logger .Errorf ("Failed to create client options: %v" , err )
77+ return nil , errors .NewInternal (err , "failed to create client options" )
7578 }
7679
7780 for _ , clientOptionsPlugin := range clientOptionsPlugins {
7881 if err := clientOptionsPlugin (ctx , co ); err != nil {
79- logger .Fatalf (err .Error ())
82+ logger .Errorf ("Failed to apply client options plugin: %v" , err )
83+ return nil , errors .NewInternal (err , "failed to apply client options plugin" )
8084 }
8185 }
8286
@@ -90,7 +94,8 @@ func NewConnWithOptions(ctx context.Context, o *Options, plugins ...Plugin) (con
9094
9195 for _ , clientPlugin := range clientPlugins {
9296 if err := clientPlugin (ctx , client ); err != nil {
93- logger .Fatalf (err .Error ())
97+ logger .Errorf ("Failed to apply client plugin: %v" , err )
98+ return nil , errors .NewInternal (err , "failed to apply client plugin" )
9499 }
95100 }
96101
0 commit comments