Skip to content

Conversation

wolfogre
Copy link
Member

This is a proposal.

There are lots of ErrXXXNotExist in models, like

// ErrUserNotExist represents a "UserNotExist" kind of error.
type ErrUserNotExist struct {
	UID   int64
	Name  string
	KeyID int64
}

// IsErrUserNotExist checks if an error is a ErrUserNotExist.
func IsErrUserNotExist(err error) bool {
	_, ok := err.(ErrUserNotExist)
	return ok
}

But sometimes I don't care what kind of "NotExist" the error is, I just want to know if it is "NotExist".

If this PR had been merged, I could do that like this:

type ErrUserNotExist struct {
	db.ErrNotExist
	// ...
}

var err error = ErrUserNotExist{}
IsErrUserNotExist(err) // true
db.IsErrNotExist(err) // true
IsErrRepoNotExist(err) // false

@wolfogre wolfogre added type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Oct 13, 2022
@wolfogre wolfogre requested a review from lunny October 13, 2022 07:29
@lafriks
Copy link
Member

lafriks commented Oct 13, 2022

Maybe we could add interface that these kind of errors could implement?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 13, 2022
@delvh
Copy link
Member

delvh commented Oct 13, 2022

See also #20891

@wolfogre
Copy link
Member Author

See also #20891

Sorry I missed it, it looks better, I'll close this one.

@wolfogre wolfogre added issue/duplicate The issue has already been reported. and removed type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Oct 13, 2022
@wolfogre wolfogre closed this Oct 13, 2022
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/duplicate The issue has already been reported. lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants