Skip to content

Conversation

@nanjiangshu
Copy link
Contributor

@nanjiangshu nanjiangshu commented Jan 15, 2026

Related issue(s) and PR(s)
This PR closes #623

Description
sda-cli returns the original message when the HTTP status code is 412. When the status code is others, still return just the status code to avoid exposing unnecessary information to the user

How to test
That unit test and integration tests pass.

@nanjiangshu nanjiangshu force-pushed the fix/download-show-useful-message-for-version-check branch from d4be298 to 8c8f08e Compare January 15, 2026 14:38
@nanjiangshu nanjiangshu force-pushed the fix/download-show-useful-message-for-version-check branch 4 times, most recently from 3f6a3a9 to 50e6547 Compare January 15, 2026 21:24
@nanjiangshu nanjiangshu force-pushed the fix/download-show-useful-message-for-version-check branch from 50e6547 to 8148824 Compare January 15, 2026 21:26
@nanjiangshu nanjiangshu force-pushed the fix/download-show-useful-message-for-version-check branch from 8148824 to a45f622 Compare January 15, 2026 21:28
@nanjiangshu nanjiangshu marked this pull request as ready for review January 16, 2026 09:33
@nanjiangshu nanjiangshu requested a review from a team as a code owner January 16, 2026 09:33
Co-authored-by: Joakim Bygdell <[email protected]>
@nanjiangshu nanjiangshu force-pushed the fix/download-show-useful-message-for-version-check branch from d41c925 to 8d50c9f Compare January 16, 2026 12:25
@jbygdell jbygdell requested a review from a team January 19, 2026 09:02
Comment on lines +433 to +440
switch res.StatusCode {
case http.StatusOK:
return resBody, nil
case http.StatusPreconditionFailed: // Return the original message from the server in case of 412
return nil, errors.New(strings.TrimSpace(string(resBody)))
default:
return nil, fmt.Errorf("server returned status %d", res.StatusCode)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch res.StatusCode {
case http.StatusOK:
return resBody, nil
case http.StatusPreconditionFailed: // Return the original message from the server in case of 412
return nil, errors.New(strings.TrimSpace(string(resBody)))
default:
return nil, fmt.Errorf("server returned status %d", res.StatusCode)
}
if res.StatusCode != http.StatusOK {
return nil, errors.New(strings.TrimSpace(string(resBody)))
}
return resBody, nil

We shouldn't treat this as a special case. It's better to always return any error string to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure if it's better to always return any error string to the user. We had a previous issue to filter error messages returned from the API and just show the HTTP code. For this special case (412), I'm pretty sure error messages returned from the API are quite clean, but not sure for all the other cases.

// Download function downloads files from the SDA by using the
// download's service APIs
func Download(args []string, configPath, version string) error {
appVersion = version
Copy link
Contributor

@KarlG-nbis KarlG-nbis Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but to me if would be cleaner if we remove the appVersion variable, and instead update the functions that uses it to take the version as a argument, eg:

func datasetCase(token, version string) error {
...
}

And we would pass the version from the Download invocation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should note this in the future refactoring issue.

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.

should show actual error message instead of just 412 when cli version does not meet the requirement

4 participants