trilium-py icon indicating copy to clipboard operation
trilium-py copied to clipboard

Upload md fails when parent note does not exist, does not forward error

Open maphew opened this issue 9 months ago • 2 comments

Code

# /// script
# dependencies = [
#   "trilium-py",
# ]
# ///
from trilium_py.client import ETAPI
server_url = 'http://localhost:8080'
token = '*******'
ea = ETAPI(server_url, token)

res = ea.upload_md_file(
    parentNoteId="import-single-md",
    file="./sample/something-2.md",
)
❯ uv run xx-debug.py
2025-03-15 10:08:09.125 | INFO     | trilium_py.client:upload_md_file:951 - /var/home/matt/dev/trilium-py/examples/uv/sample/something-2.md

portion of http://localhost:8080/#root/_hidden/_backendLog:

10:08:09.159 ERROR: post /etapi/create-note threw exception Validation failed on property 'parentNoteId': Note 'import-single-md' does not exist. with stacktrace: Error: Validation failed on property 'parentNoteId': Note 'import-single-md' does not exist.

So first problem is that the script thinks it succeeded but didn't, but the deeper issue is that trilium-py doesn't report that the server complained so we don't know anything until investigating the backend.

maphew avatar Mar 15 '25 17:03 maphew

You are welcome to make PRs to improve this behavior : )

Nriver avatar Mar 19 '25 02:03 Nriver

I'll give it a shot

maphew avatar Mar 19 '25 20:03 maphew