Skip to content

Client.CreateUpload: Invalid formatting in case of ErrUnexpectedResponse #4

@nicholasdehnen

Description

@nicholasdehnen

Client.CreateUpload returns a ErrUnexpectedResponse in the default case:

tus-go-client/client.go

Lines 217 to 218 in 5a12337

default:
err = ErrUnexpectedResponse

ErrUnexpectedResponse is a TusError, with TusError.Error() defined as:

tus-go-client/error.go

Lines 16 to 18 in 5a12337

func (te TusError) Error() string {
return fmt.Sprintf("%s: %s", te.msg, te.inner)
}

So when Error() is called on ErrUnexpectedResponse, it returns a string with invalid formatting because the inner error is unset:

unexpected HTTP response code: %!s(<nil>)

I'm assuming this is easily fixed by setting err = ErrUnexpectedResponse.WithResponse(response) in client.go.

Note that ideally TusError.WithResponse should also not panic in case the error returned by io.ReadFull isn't io.EOF, this is unexpected and undocumented, a better solution might be to set te.inner = err.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions