-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Now error values from APIs in the x/sys/windows package are syscall.Errno, even though the original API returns HRESULT value. For example, CoInitializeEx originally returns HRESULT, but windows.CoInitializeEx wraps the HRESULT value as syscall.Errno and returns it. This package doesn't distinguish Errno and HRESULT as error values, and this seems odd in terms of semantics. My understanding is Errno and HRESULT are different things. There might be a historical reason why this package does so, but in this case I'd like to know.
My proposal is to let HRESULT implement the error interface and let the APIs return it (when the value is not S_OK) instead of wrapping as Errno. This simple implementation would be enough:
func (h HRESULT) Error() string {
return fmt.Sprintf("HRESULT(%08x)", h)
}This is a breaking change and existing error checkings might no longer work, after the APIs return HRESULT instead of Errno. However, as x/sys/windows is still v0, a breaking change should be acceptable.
The controversial point is that there are some non-zero values which can be used in a successful case (e.g. S_FALSE for CoInitializeEx). In this case, implementing error might be odd. IMO my proposal is not a perfect solution but should be better than wrapping HRESULT as Errno without conditions, and improve the current semantics confusion.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status