hid
hid copied to clipboard
Modify hid.UsbWalk to return an error
trafficstars
maybe something like this (I havent tested it)
-func UsbWalk(cb func(Device)) {
- filepath.Walk(DevBusUsb, func(f string, fi os.FileInfo, err error) error {
+func UsbWalk(cb func(Device)) error {
+ err := filepath.Walk(DevBusUsb, func(f string, fi os.FileInfo, err error) error {
if err != nil || fi.IsDir() {
return nil
}
@@ -292,4 +292,5 @@ func UsbWalk(cb func(Device)) {
}
return nil
})
+ return err
}
obviously the above is not enough, the error needs to be added to the callback function as well.
Anyway, the idea is to be able to return an error from inside the cb function which propagates all the way out if it. Should make surrounding code a bit easier to read and it would be possible to abort a walk.
I don't know if your API modification policy is "stable API" or "vendor it if you want a stable API' so I'm holding off making a pull request until you hint if this is something desirable or not.