uuid icon indicating copy to clipboard operation
uuid copied to clipboard

uuid.Parse function does not handle empty string

Open ridhisikaria opened this issue 1 year ago • 1 comments

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())

ridhisikaria avatar Apr 19 '24 09:04 ridhisikaria

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

alexbozhenko avatar Jun 23 '24 23:06 alexbozhenko

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.

jensilo avatar Jul 09 '24 13:07 jensilo

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).

bormanp avatar Jul 09 '24 13:07 bormanp