google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.29k stars 363 forks source link

uuid.Parse function does not handle empty string #160

Closed ridhisikaria closed 2 months ago

ridhisikaria commented 5 months ago

In current implementation of uuid.Parse for all default cases uuid, invalidLengthError{len(s)} is returned.

Thus the returned response is not treated as error if not read correctly when used as an import

An immediate fix suggestion: return the following for default uuid length case. :

return uuid, errors.New(invalidLengthError{len(s)}.Error())

alexbozhenko commented 3 months ago

@ridhisikaria. Not sure what you mean by "not treated as error" https://go.dev/play/p/5A_muBzLgOj

jensilo commented 2 months ago

Just randomly stumbled across this. Looks like an AI-generated PR (or at least AI-found error) to me. I've gotten ChatGPT to find a pretty similar non-existent issue upon inspecting the corresponding code.

I think, the problem stems from the fact that invalidLengthError might potentially not implement the error interface, leading an LLM to highlight this as an error and suggesting to construct a "valid" error using a function it knows will always produce a valid error.

However, this makes absolutely no sense, espacially since the Parse-function is defined as: Parse(s string) (UUID, error) where it is clear that the returned error must fulfill the error-interface, otherwise the code won't compile.

@ridhisikaria if I'm doing you wrong, please explain your issue with this in more detail. Otherwise, I see no problem here.

bormanp commented 2 months ago

Closing this as an empty string does generate an error (it does not return nil). invalidLengthError{0} is a proper error and should not be confused with error(nil).