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

transport: inject info about udev rules into io/os exception #245

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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