How does the TUS protocol support validation errors

We have created an upload service with the TUS protocol using the tus-java-server library (GitHub - tomdesair/tus-java-server: Library to receive tus v1.0.0 file uploads in a Java server environment).
In our situation each file that is uploaded must be provided with some metadata, which can be placed in the header Upload-Metadata in the POST request.
We validate the content of the metadata and if the metadata does not comply to the rules we have, we want to report this back to the TUS client.
I have not found a describtion in the TUS protocol how the server can send an error response.
So my question is: what is the best way for the server to send a response describing what is invalid about the metadata?

The tus protocol does not define any specific behavior here because you can just use any error response approach that HTTP itself allows.

So in your situation, I would recommend to respond with a 400 response. The error message and details go into the response body. The client should be configured to not retry when a 400 response is received. In addition, the error object returned by the tus client usually includes the response body, so you can access the error message.

Hope that helps!