Better errors when parsing multipart
This commit is contained in:
parent
c4be680abc
commit
5fac31b9b4
1 changed files with 7 additions and 5 deletions
|
@ -23,6 +23,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -259,6 +260,7 @@ func parseMultipartRequest(w http.ResponseWriter, req *http.Request, reportDir s
|
||||||
func parseFormPart(part *multipart.Part, p *parsedPayload, reportDir string) error {
|
func parseFormPart(part *multipart.Part, p *parsedPayload, reportDir string) error {
|
||||||
defer part.Close()
|
defer part.Close()
|
||||||
field := part.FormName()
|
field := part.FormName()
|
||||||
|
partName := part.FileName()
|
||||||
|
|
||||||
var partReader io.Reader
|
var partReader io.Reader
|
||||||
if field == "compressed-log" {
|
if field == "compressed-log" {
|
||||||
|
@ -269,7 +271,7 @@ func parseFormPart(part *multipart.Part, p *parsedPayload, reportDir string) err
|
||||||
// gzip at upload time.
|
// gzip at upload time.
|
||||||
zrdr, err := gzip.NewReader(part)
|
zrdr, err := gzip.NewReader(part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrapf(err, "Error unzipping %s", partName)
|
||||||
}
|
}
|
||||||
defer zrdr.Close()
|
defer zrdr.Close()
|
||||||
partReader = zrdr
|
partReader = zrdr
|
||||||
|
@ -279,18 +281,18 @@ func parseFormPart(part *multipart.Part, p *parsedPayload, reportDir string) err
|
||||||
}
|
}
|
||||||
|
|
||||||
if field == "file" {
|
if field == "file" {
|
||||||
leafName, err := saveFormPart(part.FileName(), partReader, reportDir)
|
leafName, err := saveFormPart(partName, partReader, reportDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrapf(err, "Error saving %s %s", field, partName)
|
||||||
}
|
}
|
||||||
p.Files = append(p.Files, leafName)
|
p.Files = append(p.Files, leafName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if field == "log" || field == "compressed-log" {
|
if field == "log" || field == "compressed-log" {
|
||||||
leafName, err := saveLogPart(len(p.Logs), part.FileName(), partReader, reportDir)
|
leafName, err := saveLogPart(len(p.Logs), partName, partReader, reportDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrapf(err, "Error saving %s %s", field, partName)
|
||||||
}
|
}
|
||||||
p.Logs = append(p.Logs, leafName)
|
p.Logs = append(p.Logs, leafName)
|
||||||
return nil
|
return nil
|
||||||
|
|
Reference in a new issue