@@ -20,14 +20,14 @@ import (
2020 "database/sql"
2121 "database/sql/driver"
2222 "encoding/json"
23+ "errors"
2324 "fmt"
2425 "os"
2526 "reflect"
2627 "strconv"
2728 "time"
2829
2930 "github.com/go-sql-driver/mysql"
30- "github.com/pkg/errors"
3131
3232 "github.com/dapr/components-contrib/bindings"
3333 "github.com/dapr/kit/logger"
@@ -117,7 +117,7 @@ func (m *Mysql) Init(metadata bindings.Metadata) error {
117117
118118 err = db .Ping ()
119119 if err != nil {
120- return errors . Wrap ( err , "unable to ping the DB" )
120+ return fmt . Errorf ( "unable to ping the DB: %w" , err )
121121 }
122122
123123 m .db = db
@@ -128,21 +128,21 @@ func (m *Mysql) Init(metadata bindings.Metadata) error {
128128// Invoke handles all invoke operations.
129129func (m * Mysql ) Invoke (ctx context.Context , req * bindings.InvokeRequest ) (* bindings.InvokeResponse , error ) {
130130 if req == nil {
131- return nil , errors .Errorf ("invoke request required" )
131+ return nil , errors .New ("invoke request required" )
132132 }
133133
134134 if req .Operation == closeOperation {
135135 return nil , m .db .Close ()
136136 }
137137
138138 if req .Metadata == nil {
139- return nil , errors .Errorf ("metadata required" )
139+ return nil , errors .New ("metadata required" )
140140 }
141141 m .logger .Debugf ("operation: %v" , req .Operation )
142142
143143 s , ok := req .Metadata [commandSQLKey ]
144144 if ! ok || s == "" {
145- return nil , errors .Errorf ("required metadata not set: %s" , commandSQLKey )
145+ return nil , fmt .Errorf ("required metadata not set: %s" , commandSQLKey )
146146 }
147147
148148 startTime := time .Now ()
@@ -171,7 +171,7 @@ func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindi
171171 resp .Data = d
172172
173173 default :
174- return nil , errors .Errorf ("invalid operation type: %s. Expected %s, %s, or %s" ,
174+ return nil , fmt .Errorf ("invalid operation type: %s. Expected %s, %s, or %s" ,
175175 req .Operation , execOperation , queryOperation , closeOperation )
176176 }
177177
@@ -201,11 +201,9 @@ func (m *Mysql) Close() error {
201201}
202202
203203func (m * Mysql ) query (ctx context.Context , sql string ) ([]byte , error ) {
204- m .logger .Debugf ("query: %s" , sql )
205-
206204 rows , err := m .db .QueryContext (ctx , sql )
207205 if err != nil {
208- return nil , errors . Wrapf ( err , "error executing %s " , sql )
206+ return nil , fmt . Errorf ( "error executing query: %w " , err )
209207 }
210208
211209 defer func () {
@@ -215,7 +213,7 @@ func (m *Mysql) query(ctx context.Context, sql string) ([]byte, error) {
215213
216214 result , err := m .jsonify (rows )
217215 if err != nil {
218- return nil , errors . Wrapf ( err , "error marshalling query result for %s " , sql )
216+ return nil , fmt . Errorf ( "error marshalling query result for query: %w " , err )
219217 }
220218
221219 return result , nil
@@ -226,7 +224,7 @@ func (m *Mysql) exec(ctx context.Context, sql string) (int64, error) {
226224
227225 res , err := m .db .ExecContext (ctx , sql )
228226 if err != nil {
229- return 0 , errors . Wrapf ( err , "error executing %s " , sql )
227+ return 0 , fmt . Errorf ( "error executing query: %w " , err )
230228 }
231229
232230 return res .RowsAffected ()
@@ -237,7 +235,7 @@ func propertyToInt(props map[string]string, key string, setter func(int)) error
237235 if i , err := strconv .Atoi (v ); err == nil {
238236 setter (i )
239237 } else {
240- return errors . Wrapf ( err , "error converitng %s:%s to int" , key , v )
238+ return fmt . Errorf ( "error converting %s:%s to int: %w " , key , v , err )
241239 }
242240 }
243241
@@ -249,7 +247,7 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du
249247 if d , err := time .ParseDuration (v ); err == nil {
250248 setter (d )
251249 } else {
252- return errors . Wrapf ( err , "error converitng %s:%s to time duration" , key , v )
250+ return fmt . Errorf ( "error converting %s:%s to duration: %w " , key , v , err )
253251 }
254252 }
255253
@@ -258,14 +256,14 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du
258256
259257func initDB (url , pemPath string ) (* sql.DB , error ) {
260258 if _ , err := mysql .ParseDSN (url ); err != nil {
261- return nil , errors . Wrapf ( err , "illegal Data Source Name (DNS ) specified by %s" , connectionURLKey )
259+ return nil , fmt . Errorf ( "illegal Data Source Name (DSN ) specified by %s" , connectionURLKey )
262260 }
263261
264262 if pemPath != "" {
265263 rootCertPool := x509 .NewCertPool ()
266264 pem , err := os .ReadFile (pemPath )
267265 if err != nil {
268- return nil , errors . Wrapf ( err , "Error reading PEM file from %s" , pemPath )
266+ return nil , fmt . Errorf ( "error reading PEM file from %s: %w " , pemPath , err )
269267 }
270268
271269 ok := rootCertPool .AppendCertsFromPEM (pem )
@@ -275,13 +273,13 @@ func initDB(url, pemPath string) (*sql.DB, error) {
275273
276274 err = mysql .RegisterTLSConfig ("custom" , & tls.Config {RootCAs : rootCertPool , MinVersion : tls .VersionTLS12 })
277275 if err != nil {
278- return nil , errors . Wrap ( err , "Error register TLS config" )
276+ return nil , fmt . Errorf ( "error register TLS config: %w" , err )
279277 }
280278 }
281279
282280 db , err := sql .Open ("mysql" , url )
283281 if err != nil {
284- return nil , errors . Wrap ( err , "error opening DB connection" )
282+ return nil , fmt . Errorf ( "error opening DB connection: %w" , err )
285283 }
286284
287285 return db , nil
0 commit comments