Jakeler / ble-serial

"RFCOMM for BLE" a UART over Bluetooth low energy (4+) bridge for Linux, Mac and Windows
https://blog.ja-ke.tech/tags/#bluetooth
MIT License
277 stars 38 forks source link

Unexpected Error: FileExistsError #106

Open noduritoto opened 3 months ago

noduritoto commented 3 months ago

Note: for general support questions, please use the discussions tab. This is the template for bugs in ble-serial. Make sure you have completely read the README, searched through the issues and discussions.

Describe the bug I met a error about 'Unexpected Error: FileExistsError' How can I fix it?

Log messages The full output of ble-serial -v (with your usual parameters like -d). If it is related to BLE chracteristics please also run ble-scan -d with you device address.

Put the result into code blocks (wrap with triple backticks) to get proper formatting: $ble-serial -d 12345678989

your log could be here

$ble-serial -d 12345678989 14:08:06.889 | ERROR | main.py: Unexpected Error: FileExistsError(17, 'File exists') 14:08:06.889 | WARNING | main.py: Shutdown initiated 14:08:06.890 | INFO | main.py: Shutdown complete.

Setup (please complete the following information):

Additional Context Tricks for reproducing the issue? Results from other things you have already tried? Ideas what might be the cause, etc.

MrCocoDev commented 3 months ago

I'm not the author, but if you use the --port parameter to change the port you can circumvent this error. I am not sure why the virtual port isn't being cleaned up automatically.

Jakeler commented 3 months ago

Hi, you can delete the file if you are sure no ble-serial is running, in the console simply: rm /tmp/ttyBLE

It gets auto cleaned on a usual shutdown, but maybe the process was hard killed before, then it can't run the cleanup routine.

The tip from @MrCocoDev for using a different path should work as well.

MrCocoDev commented 3 months ago

I think if you add:

                try:
                    self.uart = UART(args.port, loop, args.mtu)
                except OSError as e:
                    # This check might be hype specific to MacOS, not sure
                    if "FileExistsError(17, 'File exists')" in repr(e):
                        raise ValueError(
                            f"Port {args.port} already exists. "
                            f"Please specify a new port or clean "
                            f"up the old port, if it is safe to do so."
                        ) from e 

You could add a lot of clarity around this issue. I happened to figure it out from an unrelated SO and a good guess, but I imagine a lot of users will just give up in frustration.

Either way, thanks for such an awesome library!