Unexpected "<nil>" Error Value
febriliankr opened this issue · 4 comments
Description:
I am encountering an unexpected issue with the Xendit payment gateway API Golang SDK. The SDK is returning a "" value as the error even when the action is successful. As a result, the err variable, which should indicate an error, is not nil, leading to incorrect error handling in the code.
Steps to Reproduce:
xenditClient := client.New(cfg.Xendit.ApiKey)
res, err = xenditClient.QRCode.CreateQRCode(params)
if err != nil {
log.Println("response", res) // returns proper response
log.Println("error", err) // outputs "<nil>"
stringErr := fmt.Sprintf("string error %w", err)
log.Println(stringErr) // outputs "%!w(*xendit.Error=<nil>)"
return res, err
}
Mention any relevant code snippets or examples.
Expected Behavior:
When the action is successful, the SDK should return nil as the error value, allowing proper error handling in the code.
Actual Behavior:
The SDK is returning "<nil>"
as the error value, resulting in err != nil
evaluating to true, and the code treating it as an error.
Additional Information:
Version of xendit-go SDK: v1.0.20
Operating system: MacOS Ventura 13.3 and Oracle Linux 8
Golang version: go version go1.20.5 linux/amd64
Can you make sure the type of err is XenditError?
I faced the same problem before then i just realize that my err is not instance of XenditError because err defined as inbuilt error, then after i change err to xenErr problem solved for me, xenErr for me indicated as XenditError
Thanks @MrWildanMD for the suggestion, yea I think this is a casting issue with our internal types. @febriliankr could you try this out? We are currently in the process of working on a new version of SDKs, so we are unable to provide much support unfortunately.
faced this issue as well. best approach for now is just calling it with a diff name (variable wise) so go won't try replacing the value of err
defined elsewhere in the scope
I believe this is solved by using github.com/xendit/xendit-go/v4