improve the returned error of `oci.NewFromTar` when the passed-in path is not a tarfile
qweeah opened this issue · 3 comments
oci.NewFromTar can be used to create a new read-only OCI store from a tarfile path. If the passed-in path doesn't point to a tarfile, currently(v2.3.1) below errors will be returned:
- If the length of the file is zero, a
failed to open OCI layout file: oci-layout: file does not exist
error will be returned - If the length of the file is not zero, an io.ErrUnexpectedEOF will be returned
As a user of oras-go SDK, I would like this function to return a unified and exported error type. Also, the error should indicate that the passed-in path doesn't point to an expected tarfile.
Hello
I would like to work on this issue.
I have tried implementing the required code changes in the PR #793 as best I could interpret them.
Please let me know if any changes are required.
@ADorigi Thanks for your contribution. After discussing with @qweeah offline, this issue is no longer valid.
The more user-friendly error messages should be handled in the CLI instead of in the oras-go
SDK.
A proper example of oci.NewFromTar
error handling would be
store, err := oci.NewFromTar(ctx, path)
if err != nil {
return fmt.Errorf("%s: invalid or corrupted oci-style tarball: %w", path, err)
}
Thanks @ADorigi for the contribution. io.ErrUnexpectedEOF already implies corrupted(invalid) tar ball file.
Also, we notice that failed to open OCI layout file: oci-layout: file does not exist
got an extra space. It's caused by missing operation in the path error. Will raise a PR to fix that.