Skip to content

Commit

Permalink
Improve error message for already existing port symlinks
Browse files Browse the repository at this point in the history
showed only a generic FileExistsError on main otherwise, which is not clear for users

fixes #106
  • Loading branch information
Jakeler committed Nov 25, 2024
1 parent 0f183c6 commit 583866b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ble_serial/ports/linux_pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ def __init__(self, symlink: str, ev_loop: asyncio.AbstractEventLoop, mtu: int):
tty.setraw(self._controller_fd, termios.TCSANOW)

self.symlink = symlink
os.symlink(self.endpoint_path, self.symlink)
try:
os.symlink(self.endpoint_path, self.symlink)
except FileExistsError:
logging.error(
f'Port "{self.symlink}" already exists! '
'Please specify a new port (with -p) or delete (rm) the port file'
' if no other ble-serial is currently using it.')
raise
logging.info(f'Port endpoint created on {self.symlink} -> {self.endpoint_path}')

def set_receiver(self, callback):
Expand Down

0 comments on commit 583866b

Please sign in to comment.