Closed ridhisikaria closed 2 months ago
@ridhisikaria. Not sure what you mean by "not treated as error" https://go.dev/play/p/5A_muBzLgOj
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.
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).
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())