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.24k stars 363 forks source link

Remove error return value from NewUUID func #83

Closed HemanthEverest closed 3 years ago

HemanthEverest commented 3 years ago

I see NewUUID internally call GetTime which returns error as a return value but this value will always be nil (https://github.com/google/uuid/blob/master/time.go#L45-L67).

So, it doesn't make any sense to return error from NewUUID when the value is always nil.

pborman commented 3 years ago

Changing this will break existing code.

When the UUID package was first implemented, in 2011, GetTime called os.Time which could return an os.Error and GetTime passed that error to its caller, NewUUID, which in turn passes it back to its caller. When changed to use time.Now() there was no longer a path that would return an error, however, the signature could not be changed without breaking backwards compatibility.

If, someday, someone decides to fully follow the standard then a host wide persistent mechanism would need to be used to assure no two processes would ever return the same time value and it would always be monotonically increasing, even across reboots. In that case I guess an error could be returned again, but the real reason is what I said above.

You can see the checkin at https://github.com/pborman/uuid/commit/e130d97558da97862b63559fa31be05c88ce3cc7#diff-9087329ff82d586a2f2e2393b726e00312bbd94506e54899e2012b93041bd698