-
Notifications
You must be signed in to change notification settings - Fork 306
Remove use of pkg/errors
- it has been deprecated and archived
#4850
Comments
/assign Mind if I take a look at this ? |
With new native |
That's a good idea to take the time to get something consistent across the board Harsha. It would be more work, but I wonder if we should get that common error handling into Either way, I like the idea of taking the opportunity to review our error handling and seeing if we can do something more consistent and better overall. |
I think that should be doable. If we create the error package on the TCE repo here in a generic way, we can port the same to the Let me scan through the entire repo once and get a list of all possible ways the error packages are being consumed and see how we can replace them with a custom error package tailed made for the tanzu use-cases. |
❯ rg pkg/errors -g "*.go"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/helpers.go
7: "sigs.k8s.io/kind/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/write.go
10: "sigs.k8s.io/kind/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/read.go
11: "sigs.k8s.io/kind/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/encode.go
10: "sigs.k8s.io/kind/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/merge.go
9: "sigs.k8s.io/kind/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/utils/lock.go
12: "github.com/pkg/errors"
extensions/docker-desktop/apps/clustermgr/pkg/kubeconfig/internal/kubeconfig/remove.go
9: "sigs.k8s.io/kind/pkg/errors" This is not too many. I see we are using a few Should be pretty straight forward to get us going. I will open a DRAFT PR with proposed changes and we can get it reviewed. |
package errors
import "fmt"
type Reason string
const (
ReasonUnknown Reason = "Unknown"
ReasonLockFailed Reason = "LockFailed"
ReasonMergeFailed Reason = "MergeFailed"
)
type TanzuError struct {
ErrorDetails ErrorDetails `json:"errorDetails"`
}
type ErrorDetails struct {
Message string `json:"message,omitempty"`
Reason Reason `json:"reason,omitempty"`
Err error `json:"err"`
}
func (t *TanzuError) Error() string {
return fmt.Sprintf("%s: %s (%s)", t.ErrorDetails.Reason, t.ErrorDetails.Message, t.ErrorDetails.Err)
}
func NewLockFailed(err error, configPath string) *TanzuError {
return &TanzuError{
ErrorDetails: ErrorDetails{
Reason: ReasonLockFailed,
Message: fmt.Sprintf("failed to lock config file %s", configPath),
Err: err,
},
}
}
func NewMergeFailed(err error, configPath string) *TanzuError {
return &TanzuError{
ErrorDetails: ErrorDetails{
Reason: ReasonMergeFailed,
Message: fmt.Sprintf("failed to get kubeconfig (%s) to merge", configPath),
Err: err,
},
}
} @stmcginnis @jpmcb Here is an example of the error package I am thinking. Is this inline with what you have in mind or do I need to tune some bits of it ? |
Looks great Harsha! |
great. Let me open a PR as early as tomorrow with this change and migrate all of the items mentioned above to use this common |
❯ go mod why github.com/pkg/errors
# github.com/pkg/errors
github.com/docker/docker/client
github.com/pkg/errors I was cleaning up things and noticed that we will still be left with some dependency on the |
@stmcginnis @jpmcb I came across https://github.com/zchee/go-analyzer/tree/main/pkgerrors in the k8s Kind slack group. |
I'm actually not a big fan of this. Go 2 isn't too far away and will include in it's standard library a complete overhaul of error handling. I'd prefer we approach this using current paradigms in Go (probably through My proposal: close #4885 in favor of removing |
Works for me. I will re-open the PR with the suggested changes. |
@jpmcb @stmcginnis PTAL at the #4914 I have opened a new one based on comment from @jpmcb |
Feature Request
Found out today the
pkg/errors
project had been looking for maintainers for some time and had finally decided to archive the project. We should move away from using it.pkg/errors#245
Describe alternatives you've considered
A few alternatives:
fmt.Error
insteadThe text was updated successfully, but these errors were encountered: