Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved error message request for usb.c #585

Closed
petertorelli opened this issue Apr 10, 2017 · 5 comments · Fixed by #883
Closed

improved error message request for usb.c #585

petertorelli opened this issue Apr 10, 2017 · 5 comments · Fixed by #883

Comments

@petertorelli
Copy link
Collaborator

Ubuntu 16.10 requires root access to open a device. I often forget this since I routinely switch between macOS, Windows and Linux. This is a bit pedantic, but the WLOG messages in src/usb.c aren't succinct enough or are incorrect. I changed them to the following as a user-experience improvement, but I don't have branch permissions:

diff --git a/src/usb.c b/src/usb.c
index 03ac1ab..33bb350 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -959,7 +959,7 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {
         struct libusb_device_descriptor desc;
         int r = libusb_get_device_descriptor(dev, &desc);
         if (r < 0) {
-            WLOG("failed to get libusb device descriptor\n");
+            WLOG("failed to get libusb device descriptor during count (libusb error: %d)\n", ret);
             break;
         }
 
@@ -983,7 +983,7 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {
         struct libusb_device_descriptor desc;
         ret = libusb_get_device_descriptor(dev, &desc);
         if (ret < 0) {
-            WLOG("failed to get libusb device descriptor\n");
+            WLOG("failed to get libusb device descriptor during open (libusb error: %d)\n", ret);
             break;
         }
 
@@ -997,7 +997,10 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {
 
         ret = libusb_open(dev, &handle);
         if (ret < 0) {
-            WLOG("failed to get libusb device descriptor\n");
+            if (ret == LIBUSB_ERROR_ACCESS)
+                WLOG("failed to open USB device (LIBUSB_ERROR_ACCESS), try running as root?\n");
+            else
+                WLOG("failed to open USB device (libusb error: %d)\n", ret);
             break;
         }
@xor-gate
Copy link
Member

xor-gate commented Apr 11, 2017 via email

@petertorelli
Copy link
Collaborator Author

@xor-gate I'd love to but I don't have permissions to make a branch to make a pull request. :)

@xor-gate
Copy link
Member

Hi @petertorelli,

Probably you are not used to Git workflow -> Fork repo (github) -> Create feature Branch -> Create Pull request to upstream -> Merge.

You should read some documentation, because I only accept PRs.

https://help.github.com/articles/creating-a-pull-request-from-a-fork/

Thank you,
Jerry

@xor-gate
Copy link
Member

xor-gate commented May 9, 2017

Ping @petertorelli, probably the message should not be that you running as root but having insufficient permissions to access the device. Please submit a PR if you want this in master.

@Nightwalker-87
Copy link
Member

@petertorelli: Please submit this proposal in form of a PR so that it can be properly addressed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants