Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: archive/zip: enhance ErrFormat error string with more granular details of failure #64353

Open
niksw7 opened this issue Nov 23, 2023 · 3 comments
Labels
Milestone

Comments

@niksw7
Copy link

niksw7 commented Nov 23, 2023

Proposal Details

The current code for reading zip
read,err := zip.OpenReader("filename.zip")
In cases of error due to headers etc, it's very difficult to debug without changing the golang source code(And adding logs there). The error just states "zip: not a valid zip file".
It would be beneficial to know why the zip is not valid. So adding a proposal to make the errors here more clear with exact reason for the zip file being invalid

@gopherbot gopherbot added this to the Proposal milestone Nov 23, 2023
@seankhliao
Copy link
Member

what sort of API (custom error type?) is being proposed here?

@dmitshur dmitshur changed the title proposal: archive/zip: : Enhancing ErrFormat error string with more granular details of failure proposal: archive/zip: enhance ErrFormat error string with more granular details of failure Nov 23, 2023
@nnzv
Copy link

nnzv commented Nov 25, 2023

@niksw7, to provide a clearer understanding of the issue, it's advisable to utilize the unzip utility to decompress the file. There are multiple approaches to replicating the error, such as creating an empty file and attempting to read the zip file.

% touch foo.zip
package main

import (
    "fmt"
    "os"
    "archive/zip"
)

func main() {
    _, err := zip.OpenReader("foo.zip")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}
% go run main.go
zip: not a valid zip file
exit status 1
% unzip foo.zip
Archive:  foo.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of foo.zip or
        foo.zip.zip, and cannot find foo.zip.ZIP, period.

@niksw7
Copy link
Author

niksw7 commented Nov 26, 2023

@nnzv ,
I am speaking from the archive/zip package error messages.
There are lot of use cases, where from a golang code we have to copy few files from zip. So a more clear error message would help in debugging. I will try to add few test cases for it to ellaborate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants