Closed corburn closed 6 years ago
Just came to file this same bug. I am rewriting some code to unpack over the New
panic potential, and decided to detect and find errors myself. Go over to the documentation for NewRandom
and the documentation says it panics, but the signature and the code itself implies that it returns an error I can manage myself.
First typo was addressed in https://github.com/google/uuid/commit/0614758b5f5e81f4e7d87184b9d97fa4385f2842
second typo is being addressed in https://github.com/google/uuid/pull/27/commits/bb91e0b0e28d478ae15f8caad3ab9fa6fd48ab4e
New() calling panic is deceptive. The developer should have control over calling Must(NewRandom()) directly (since changing New() to return an error would be a breaking change for anyone using the library to date). A New() that fails should set the UUID to all 0, and the UUID can be validated with a secondary function IsValid() or something stupid.
New is often used as a global:
var instance = uuid.New()
New should never fail unless your random number generated is broken. A bad random number generator is probably worth panicing over.
I am closing this out as I don't think this will change.
Typos
'from' is repeated twice in this comment:
https://godoc.org/github.com/google/uuid#NewRandom
NewRandom()
returns an error, not a panic:https://godoc.org/github.com/google/uuid#NewRandom
Why does New panic?
It is surprising
New()
panics when compared to thehtml/template
package, for example, where functions that panic include the word Must:https://godoc.org/github.com/google/uuid#New