tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
3.05k stars 475 forks source link

failed to parse hook response... #1051

Closed baierDev closed 8 months ago

baierDev commented 9 months ago

Question I want to show (send) the actual "processing-state" of a pre-finish-hook to the client... How I make this to work ?

In my test-setup, i try to "simulate" a processing time with simple delay...

pre-finish file:

#!/usr/bin/env python3
import time

print('start processing')
time.sleep(5)
print('processing finished')

The tusd-log show me:

2023/12/20 12:08:43.401828 level=ERROR event=HookInvocationError type=pre-finish id=b72d71791322cb27bd824c721015c542 error="failed to parse hook response: invalid character 's' looking for beginning of value, response was: start processing\nprocessing finished\n"
2023/12/20 12:08:43.401875 level=ERROR event=InternalServerError method=PATCH path=b72d71791322cb27bd824c721015c542 requestId="" id=b72d71791322cb27bd824c721015c542 message="failed to parse hook response: invalid character 's' looking for beginning of value, response was: start processing\nprocessing finished\n"
2023/12/20 12:08:43.401912 level=INFO event=ResponseOutgoing method=PATCH path=b72d71791322cb27bd824c721015c542 requestId="" id=b72d71791322cb27bd824c721015c542 status=500 body="ERR_INTERNAL_SERVER_ERROR: failed to parse hook response: invalid character 's' looking for beginning of value, response was: start processing\nprocessing finished\n\n"

Setup details

Acconut commented 9 months ago

The stdout from hooks is parsed as JSON, so it expects a JSON object to be printed to stdout. If you want to log something, you should write that to stderr.

baierDev commented 9 months ago

OK, thank you!

Can you give me a simple "static" code-sample how the python script (object) should look like ?

This has no errors, but how to read the output on client ?

#!/usr/bin/env python3
import time,json

msg1 = {"body":"start processing"}
msg2 = {"testmessage":"processing finished"}

y1 = json.dumps(msg1)
y2 = json.dumps(msg2)

print(y1)

time.sleep(5)
Acconut commented 9 months ago

Please have a look at https://github.com/tus/tusd/tree/main/examples and https://github.com/tus/tusd/blob/main/docs/hooks.md#common-uses for examples.

Acconut commented 8 months ago

Closing this issue due to inactivity. Feel free to leave a comment if you want to continue the discussion :)