This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 37870f258 fix: improve error handling in auth sign_util.go (#2955)
37870f258 is described below

commit 37870f258d3aa9aa2903d3a68e549e37a3a30626
Author: CAICAII <[email protected]>
AuthorDate: Tue Jul 29 13:19:49 2025 +0800

    fix: improve error handling in auth sign_util.go (#2955)
    
    Improve error messages in SignWithParams and toBytes functions to provide 
more specific and useful error information. Replace generic error messages with 
detailed error descriptions that include the original error cause. Use 
fmt.Errorf with %w verb for better error wrapping practices.
    
    Signed-off-by: yxw <[email protected]>
---
 filter/auth/sign_util.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/filter/auth/sign_util.go b/filter/auth/sign_util.go
index 94c157c16..654547f07 100644
--- a/filter/auth/sign_util.go
+++ b/filter/auth/sign_util.go
@@ -22,7 +22,7 @@ import (
        "crypto/sha256"
        "encoding/base64"
        "encoding/json"
-       "errors"
+       "fmt"
        "strings"
 )
 
@@ -43,8 +43,7 @@ func SignWithParams(params []any, metadata, key string) 
(string, error) {
 
        data := append(params, metadata)
        if bytes, err := toBytes(data); err != nil {
-               // TODO
-               return "", errors.New("data convert to bytes failed")
+               return "", fmt.Errorf("failed to convert data to bytes: %w", 
err)
        } else {
                return doSign(bytes, key), nil
        }
@@ -52,7 +51,7 @@ func SignWithParams(params []any, metadata, key string) 
(string, error) {
 
 func toBytes(data []any) ([]byte, error) {
        if bytes, err := json.Marshal(data); err != nil {
-               return nil, errors.New("")
+               return nil, fmt.Errorf("failed to marshal data to JSON: %w", 
err)
        } else {
                return bytes, nil
        }

Reply via email to