Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handling help? #19

Open
cidrblock opened this issue Jan 26, 2024 · 3 comments · May be fixed by #20
Open

Exception handling help? #19

cidrblock opened this issue Jan 26, 2024 · 3 comments · May be fixed by #20
Assignees

Comments

@cidrblock
Copy link

cidrblock commented Jan 26, 2024

Hey there,

Thanks for making this project. I'm trying to write a little chat app over AX.25 and was trying to catch to errors.

The first I figured out, if direwolf isn't running the device never transitons to OPEN, so I can catch that:

while self.device.state != KISSDeviceState.OPEN:
            msg = f"Waiting for direwolf connection... attempt {i}/{max_attempts}"
            print(msg, end="\r")  # noqa: T201
            if i > max_attempts:
                msg = "Cannot connect to direwolf. Is it running?"
                LOGGER.critical(msg)
                sys.exit(1)

            await asyncio.sleep(1)
            i += 1

The second, which I cannot figure out, is if direwolf disappears after the device was open.

raw_frame = AX25RawFrame(
                destination=dest,
                source=self.callsign,
                control=0,
                payload=payload,
            )
interface.transmit(raw_frame)

In this case if direwolf is no longer running I get the following:

Unhandled exception in event loop:
  File "/usr/lib64/python3.12/asyncio/events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
  File "/home/bthornto/github/ax25/venv/lib64/python3.12/site-packages/aioax25/kiss.py", line 321, in _send_data
    self._send_raw_data(data)
  File "/home/bthornto/github/ax25/venv/lib64/python3.12/site-packages/aioax25/kiss.py", line 448, in _send_raw_data
    self._transport.write(data)
    ^^^^^^^^^^^^^^^^^^^^^

Exception 'NoneType' object has no attribute 'write'

Any suggestions or pointers on how to catch this one? I would like to gracefully exit the app when it happens.

Thanks for any info/suggestions,

Brad

@sjlongland
Copy link
Owner

Ahh good question, see the connection is not meant to disappear, so there's been no real thought into that sort of error handling.

Most of the effort has gone towards actually getting the AX.25 protocol stack working.

@cidrblock
Copy link
Author

Thanks for the response. If I get a chance to dig in a little deeper I'll see if I can help here.

I'm still chipping away at my project, hope to have something shareable soon.

-Brad

@sjlongland
Copy link
Owner

Sorry for the long delay… could you have a look at https://github.com/sjlongland/aioax25/tree/bugfix/issue19-missing-device and see if that helps catch the error and deal with it?

@sjlongland sjlongland self-assigned this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants