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 authored and matejcik committed Apr 3, 2018
1 parent 7c08800 commit 12c58ce
Show file tree
Hide file tree
Showing 2 changed files with 13 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
7 changes: 6 additions & 1 deletion trezorlib/transport/webusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import atexit
import usb1
import sys

from ..protocol_v1 import ProtocolV1
from ..protocol_v2 import ProtocolV2
Expand All @@ -46,7 +47,11 @@ def open(self, interface):
if self.count == 0:
self.handle = self.device.open()
if self.handle is None:
raise Exception('Cannot open device')
if sys.platform.startswith('linux'):
args = ('Do you have udev rules installed? https://github.com/trezor/trezor-common/blob/master/udev/51-trezor.rules', )
else:
args = ()
raise IOError('Cannot open device', *args)
self.handle.claimInterface(interface)
self.count += 1

Expand Down

0 comments on commit 12c58ce

Please sign in to comment.