Skip to content

Commit 63a8027

Browse files
committed
Use FailureError for Cause type
1 parent 01082b0 commit 63a8027

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

nexus/api.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package nexus
55

66
import (
7-
"errors"
87
"fmt"
98
"mime"
109
"net/url"
@@ -46,7 +45,11 @@ func NewOperationFailedError(message string) *OperationError {
4645
State: OperationStateFailed,
4746
Message: message,
4847
// Also setting Cause as a temporary workaround for compatibility with older servers.
49-
Cause: errors.New(message),
48+
Cause: &FailureError{
49+
Failure: Failure{
50+
Message: message,
51+
},
52+
},
5053
}
5154
}
5255

@@ -57,7 +60,11 @@ func OperationFailedErrorf(format string, args ...any) *OperationError {
5760
State: OperationStateFailed,
5861
Message: fmt.Sprintf(format, args...),
5962
// Also setting Cause as a temporary workaround for compatibility with older servers.
60-
Cause: fmt.Errorf(format, args...),
63+
Cause: &FailureError{
64+
Failure: Failure{
65+
Message: fmt.Sprintf(format, args...),
66+
},
67+
},
6168
}
6269
}
6370

@@ -68,7 +75,11 @@ func NewOperationCanceledError(message string) *OperationError {
6875
State: OperationStateCanceled,
6976
Message: message,
7077
// Also setting Cause as a temporary workaround for compatibility with older servers.
71-
Cause: errors.New(message),
78+
Cause: &FailureError{
79+
Failure: Failure{
80+
Message: message,
81+
},
82+
},
7283
}
7384
}
7485

@@ -79,7 +90,11 @@ func OperationCanceledErrorf(format string, args ...any) *OperationError {
7990
State: OperationStateCanceled,
8091
Message: fmt.Sprintf(format, args...),
8192
// Also setting Cause as a temporary workaround for compatibility with older servers.
82-
Cause: fmt.Errorf(format, args...),
93+
Cause: &FailureError{
94+
Failure: Failure{
95+
Message: fmt.Sprintf(format, args...),
96+
},
97+
},
8398
}
8499
}
85100

@@ -89,7 +104,11 @@ func OperationErrorf(state OperationState, format string, args ...any) *Operatio
89104
State: state,
90105
Message: fmt.Sprintf(format, args...),
91106
// Also setting Cause as a temporary workaround for compatibility with older servers.
92-
Cause: fmt.Errorf(format, args...),
107+
Cause: &FailureError{
108+
Failure: Failure{
109+
Message: fmt.Sprintf(format, args...),
110+
},
111+
},
93112
}
94113
}
95114

@@ -190,7 +209,11 @@ func HandlerErrorf(typ HandlerErrorType, format string, args ...any) *HandlerErr
190209
Type: typ,
191210
Message: fmt.Sprintf(format, args...),
192211
// Also setting Cause as a temporary workaround for compatibility with older servers.
193-
Cause: fmt.Errorf(format, args...),
212+
Cause: &FailureError{
213+
Failure: Failure{
214+
Message: fmt.Sprintf(format, args...),
215+
},
216+
},
194217
}
195218
}
196219

nexus/failure.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ func (e knownErrorFailureConverter) ErrorToFailure(err error) (Failure, error) {
129129
return Failure{}, err
130130
}
131131
f.Cause = &c
132-
} else {
133-
// Temporary workaround for compatibility with old servers that don't support handler error messages.
134-
typedErr.Cause = fmt.Errorf("%s", typedErr.Message)
135132
}
136133
return f, nil
137134
case *OperationError:
@@ -164,9 +161,6 @@ func (e knownErrorFailureConverter) ErrorToFailure(err error) (Failure, error) {
164161
return Failure{}, err
165162
}
166163
f.Cause = &c
167-
} else {
168-
// Temporary workaround for compatibility with old servers that don't support handler error messages.
169-
typedErr.Cause = fmt.Errorf("%s", typedErr.Message)
170164
}
171165
return f, nil
172166
default:

0 commit comments

Comments
 (0)