Skip to content

Conversation

@Foutete
Copy link
Contributor

@Foutete Foutete commented Sep 19, 2025

When an USB Device can't be accessed, snagrecover prints a generic error message stating to check presence
and access right.
Improve this by testing if the USB error is a permission error. If so log an error message and some hints
on how to solve it.

@Foutete Foutete force-pushed the usb_access_permission branch 2 times, most recently from 4cd9975 to 9f72262 Compare September 22, 2025 08:57
Copy link
Collaborator

@rgantois rgantois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I've requested a few changes.

When an USB Device can't be accessed, snagrecover prints
a generic error message stating to check presence
and access right.
Improve this by testing if the USB error is a permission
error. If so log an error message and some hints
on how to solve it.

Signed-off-by: François Foltete <[email protected]>
@Foutete Foutete force-pushed the usb_access_permission branch from 9f72262 to 74a6591 Compare November 8, 2025 15:13
@Foutete
Copy link
Contributor Author

Foutete commented Nov 8, 2025

Hi Romain :) ! Finally took some time to work on this PR, tell me if it looks good for you.

Copy link
Collaborator

@rgantois rgantois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi François! Thanks for the corrections! There are still a couple of things to straighten out and then we should be good to merge :)

return dev
try:
# check for device access error on last retry
if ready_check(dev, raise_access_err=(i == retries)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready_check doesn't necessarily support the raise_access_err argument, so this could break.
Since the access rights permissions check is a generic operation, it would be better to separate it from ready_check, which can be customized for different USB protocols. You can define a separate function for it e.g. permissions_check, and call it directly from get_usb.

"The following udev rule grants access to the USB device:"
)
logger.error(
f'SUBSYSTEM=="usb", ATTRS{{idVendor}}=="{dev.idProduct:04x}", ATTRS{{idProduct}}=="{dev.idVendor:04x}", MODE="0660", TAG+="uaccess"'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this during the first review, but idProduct and idVendor are swapped here.

)
elif sys.platform == "win32":
logger.error(
f"Please check that the 'libusb-win32' driver is bound to this USB device ID: {dev.idProduct:04x}:{dev.idVendor:04x}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and idProduct and idVendor are also swapped here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants