Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: clarify returned error #98

Merged
merged 1 commit into from
Jan 13, 2025
Merged

container: clarify returned error #98

merged 1 commit into from
Jan 13, 2025

Conversation

MichaelMure
Copy link
Collaborator

No description provided.

@@ -101,14 +101,12 @@ func (ctn Reader) GetToken(cid cid.Cid) (token.Token, error) {
}

// GetDelegation is the same as GetToken but only return a delegation.Token, with the right type.
// If not found, delegation.ErrDelegationNotFound is returned.
func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) {
tkn, err := ctn.GetToken(cid)
if errors.Is(err, ErrNotFound) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using errors.Is here implies the container can return other types of errors. If so, why was the next code block removed? If not, why not use err != nil here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That document the semantic ("this is the error I expected") ... but that can be a comment I suppose?

Copy link
Collaborator

@smoyer64 smoyer64 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems a bit fragile - if ctn.GetToken is later changed to return another type of error, tkn will be nil and you'll happily type that to a *delegation.Token on L110. Are we checking for a (*delgation.Token)(nil) everywhere downstream of this call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and then you'd silently bubble up a new type of error, even though something should likely be done about it. I'm not sure there is a perfect solution here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed anyway.

@MichaelMure MichaelMure merged commit 0c6717c into main Jan 13, 2025
6 checks passed
@MichaelMure MichaelMure deleted the container-err branch January 13, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants