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

Encode, EncodeName: drop error from function signature #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flokli
Copy link

@flokli flokli commented Aug 20, 2022

This makes it cleaner that this function doesn't return errors, shuts up
linters complaining about ignoring errors etc.

Considering go-multihash is v0.x.y, changing that signature should be
fine.

This makes it cleaner that this function doesn't return errors, shuts up
linters complaining about ignoring errors etc.

Considering go-multihash is v0.x.y, changing that signature should be
fine.
@rvagg rvagg self-assigned this Sep 27, 2022
@BigLep BigLep added the P3 Low: Not priority right now label Oct 4, 2022
Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

I think I'm in favour of this; I was just writing some code that used this and forgot that I didn't even need to write the error handling code.

We could bump minor version for this and just document it clearly.

@Stebalien you blocked the previous attempt to remove this @ #136 (comment) so you may want to weigh in here whether you still think it'd be annoying, even if we just did this as a single change with a semver-minor bump to go with it.

/cc @willscott @masih for more input if you have any

@rvagg
Copy link
Member

rvagg commented Jan 30, 2023

maybe I should be more cautious; I'm still having recurring pain from the go-cid break in 0.3 and the go-ipld-format ipld.NotFound break and maybe this would be just as bad since it's so low down in our stack

@masih
Copy link
Member

masih commented Jan 30, 2023

I am curious why the existing implementation of Ecode does not perform validation; For example, is it OK to do multihash.Encode([]byte("fish"), multihash.SHA2_256) where the length of the given digest does not match the expected length of the given multihash code?

Assuming validation would be useful here, considering error is already in the function signature would it make sense to instead implement validation?

@ribasushi
Copy link

@masih
Copy link
Member

masih commented Jan 30, 2023

Interesting; thanks @ribasushi

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

I would like this change, but only if someone is willing to actually fix the fallout. Which is going to be quite a bit of work for such a small change.

}

// EncodeName is like Encode() but providing a string name
// instead of a numeric code. See Names for allowed values.
func EncodeName(buf []byte, name string) ([]byte, error) {
func EncodeName(buf []byte, name string) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

We should be returning an error if the name isn't known. Otherwise, we just default to 0 which is definitely wrong.

@rvagg
Copy link
Member

rvagg commented Jan 30, 2023

but only if someone is willing to actually fix the fallout

yeah .. I'm having flashbacks to go-cid@0.3 pain and the way the libp2p breaking change straddle that and has taken a couple of years to get past; I don't think I want to deal with that

I think we might have to pass on this.

@flokli I don't suppose you're interested in pivoting this PR to just return an error from EncodeName where it's not in Names rather than removing errors? No problems if you're not interested, I understand it's quite a departure from your original ask.

@flokli
Copy link
Author

flokli commented Jan 31, 2023

but only if someone is willing to actually fix the fallout

yeah .. I'm having flashbacks to go-cid@0.3 pain and the way the libp2p breaking change straddle that and has taken a couple of years to get past; I don't think I want to deal with that

Well, this is a simple function signature change. On bumping the version, it's immediately shown by the compiler that the called function EncodeName only returns one parameter. It's a simple chore, I don't see how it can be that much of a pain.

@flokli I don't suppose you're interested in pivoting this PR to just return an error from EncodeName where it's not in Names rather than removing errors? No problems if you're not interested, I understand it's quite a departure from your original ask.

Everyone has been ignoring the err parameter so far anyways, I don't see how adding meaning now will actually get anyone to look at it :-/

@Stebalien
Copy link
Member

@flokli unfortunately, that's not the case due to dependency version rules and the fact that this repo contains a core type in interfaces, not some internal detail. Changing this is a massive pain. E.g.:

  1. Package X updates go-multihash.
  2. Package Y doesn't go-multihash.
  3. Package Z depends on X and Y and can't update X until Y updates go-multihash.

Worse, many packages that depend on go-multihash aren't controlled by the same author.

Basically, either:

  1. Everything needs to update in lock-step.
  2. There needs to be a major version bump with a shim that aliases the new version's multihash type to the old versions multihash type (to avoid splitting the ecosystem across two versions).

@Stebalien
Copy link
Member

Everyone has been ignoring the err parameter so far anyways, I don't see how adding meaning now will actually get anyone to look at it :-/

That's the user's problem, honestly. If users are ignoring errors, there's nothing we can do to help them.

@Stebalien
Copy link
Member

We'll eventually need to make breaking changes to this repo. E.g., to implement #29. That's a good reason to force the mass upgrade. Until then, I'm still of the opinion that this just isn't worth fixing.

@flokli
Copy link
Author

flokli commented Feb 1, 2023

Everyone has been ignoring the err parameter so far anyways, I don't see how adding meaning now will actually get anyone to look at it :-/

That's the user's problem, honestly. If users are ignoring errors, there's nothing we can do to help them.

Well, that's what we do in the example code on the main README:

image

I mean, the comment is a bit confusing, because it doesn't elaborate which error can be ignored.

But looking at the docstring of Encode, we document the error as "legacy", which further encourages people to ignore it:

image

So independent of the discussion on when/how we can change signatures, is this something that can be ignored or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Low: Not priority right now
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants