Skip to content

fix: include OCS error response bodies in logged errors - #255

Open
cestercian wants to merge 1 commit into
nextcloud:mainfrom
cestercian:fix/log-ocs-error-body
Open

cestercian wants to merge 1 commit into
nextcloud:mainfrom
cestercian:fix/log-ocs-error-body

Conversation

@cestercian

Copy link
Copy Markdown

Fixes #254

str(NextcloudException) only gives the status and reason, so when e.g. scheduling the LLM task fails with a 412 the log never shows what the server actually said.

This adds format_exception() to ex_app/lib/logger.py. It returns the usual traceback and then walks the cause/context chain, appending OCS response for [status]: <body> for every NextcloudException that carries a response (capped at 2000 chars). The walk matters because nc_model.py re-raises some of these as Exception(...) from e. AsyncNextcloudApp gives you niquests AsyncResponses, where .text is a coroutine, so the helper is async and awaits it (it also handles the sync Response str). If reading the body fails, it just falls back to the plain traceback.

The error logs in main.py (fetching the next task, streaming, task failure, reporting) now use it. Those go to stdout and to the Nextcloud log through log().

There is no test suite in the repo, so I checked it locally against nc-py-api 0.30.3 with a small script covering sync and async responses, a wrapped exception, a response whose body cannot be read, and a non-Nextcloud exception. I ran it with -W error so an un-awaited coroutine would fail it.

Signed-off-by: Cestercian <183791452+cestercian@users.noreply.github.com>
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 this pull request may close these issues.

Include the OCS API errors in the error logs printed and reported to nextcloud

1 participant