Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
transport: inject info about udev rules into io/os exception
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Mar 30, 2018
1 parent 5ce254c commit 644c4f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion trezorlib/transport/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import hid
import os
import sys

from ..protocol_v1 import ProtocolV1
from ..protocol_v2 import ProtocolV2
Expand All @@ -39,7 +40,12 @@ def __init__(self, path):
def open(self):
if self.count == 0:
self.handle = hid.device()
self.handle.open_path(self.path)
try:
self.handle.open_path(self.path)
except (IOError, OSError) as e:
if sys.platform.startswith('linux'):
e.args = e.args + ('Do you have udev rules installed? https://github.com/trezor/trezor-common/blob/master/udev/51-trezor.rules', )
raise e
self.handle.set_nonblocking(True)
self.count += 1

Expand Down
2 changes: 1 addition & 1 deletion trezorlib/transport/webusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def open(self, interface):
if self.count == 0:
self.handle = self.device.open()
if self.handle is None:
raise Exception('Cannot open device')
raise IOError('Cannot open device', 'Do you have udev rules installed? https://github.com/trezor/trezor-common/blob/master/udev/51-trezor.rules')
self.handle.claimInterface(interface)
self.count += 1

Expand Down

0 comments on commit 644c4f3

Please sign in to comment.