Skip to content

Commit

Permalink
wip: error debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Liaw committed Jan 3, 2025
1 parent c62c317 commit fb1bc30
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"k8s.io/klog/v2"

crusoeapi "github.com/crusoecloud/client-go/swagger/v1alpha5"
)
Expand Down Expand Up @@ -130,16 +131,23 @@ func GetAsyncOperationResult[T any](ctx context.Context, op *crusoeapi.Operation
// additional information which is present in the response. The error
// is returned unchanged if it cannot be unpacked.
func UnpackSwaggerErr(original error) error {
klog.Infof("original error: %v", original)
swagErr := &crusoeapi.GenericSwaggerError{}
if ok := errors.As(original, swagErr); !ok {
return original
}
klog.Infof("swagger error: %v", swagErr.Error())
klog.Infof("swagger body: %v", swagErr.Body())
klog.Infof("swagger model: %v", swagErr.Model())

var model crusoeapi.ErrorBody
err := json.Unmarshal(swagErr.Body(), &model)
if err != nil {
klog.Infof("failed to unmarshal error body: %v", err)

return original
}
klog.Infof("unmarshaled model: %v", model)

// some error messages are of the format "rpc code = ... desc = ..."
// in those cases, we extract the description and return it
Expand Down

0 comments on commit fb1bc30

Please sign in to comment.