Skip to content

Conversation

jiparis
Copy link
Member

@jiparis jiparis commented Nov 9, 2023

Gracefully handle empty files uploads.

Closes #380

Signed-off-by: Jose I. Paris <jiparis@gmail.com>
@migmartri migmartri changed the title fix(cli): handle empty files description fix(cli): handle empty files Nov 10, 2023
}

if info.Size() == 0 {
a.Logger.Info().Msg("the file is empty, nothing to upload")
Copy link
Contributor

@buccarel buccarel Nov 10, 2023

Choose a reason for hiding this comment

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

I have a context question, most likely for @migmartri, but anybody who knows the answer is welcome to reply ofc.

What is the context for these files?
Would someone find legit, in the generic scenario, to produce and upload an empty file?
This implementation is returning here, so client.UploadFile(...) is not being called at all.

Copy link
Member

@migmartri migmartri Nov 10, 2023

Choose a reason for hiding this comment

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

Interesting point.

I think you are right, it doesn't harm to upload empty files. In fact, artifact material types in attestations can be empty, but this code doesn't affect that (this is only for chainloop artifact upload cmd.)

The change in uploader.go is in fact what fixes the original panic #380, so I think it's ok if we remove

if info.Size() == 0 {
		a.Logger.Info().Msg("the file is empty, nothing to upload")
...

and just keep the change at internal/casclient/uploader.go.

What do you think?

Note: This implementation is based on my prescription offline, so any blame is on me :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I'll update the PR with your sugested changes. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok perfect. I'll request changes to remember not to merge this until it's fixed.
Thanks.

Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

Adding some comments to reply to @buccarel

}

if info.Size() == 0 {
a.Logger.Info().Msg("the file is empty, nothing to upload")
Copy link
Member

@migmartri migmartri Nov 10, 2023

Choose a reason for hiding this comment

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

Interesting point.

I think you are right, it doesn't harm to upload empty files. In fact, artifact material types in attestations can be empty, but this code doesn't affect that (this is only for chainloop artifact upload cmd.)

The change in uploader.go is in fact what fixes the original panic #380, so I think it's ok if we remove

if info.Size() == 0 {
		a.Logger.Info().Msg("the file is empty, nothing to upload")
...

and just keep the change at internal/casclient/uploader.go.

What do you think?

Note: This implementation is based on my prescription offline, so any blame is on me :)

Signed-off-by: Jose I. Paris <jiparis@gmail.com>
Copy link
Contributor

@buccarel buccarel left a comment

Choose a reason for hiding this comment

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

Waiting for the fix we agreed on

Copy link
Member

@migmartri migmartri left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@migmartri
Copy link
Member

Waiting for the fix we agreed on

@buccarel ptal, it seems that the fix is now up.

@jiparis jiparis requested a review from buccarel November 12, 2023 22:46
@migmartri migmartri merged commit 36237b0 into chainloop-dev:main Nov 13, 2023
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.

empty files causes client error

3 participants