Skip to content

Commit

Permalink
Merge pull request #9 from uploadcare/fix/no-fileinfo-panic
Browse files Browse the repository at this point in the history
Fix panic when reading FileInfo from response
  • Loading branch information
rsedykh authored Dec 23, 2020
2 parents f0f9543 + 784c0fc commit 5e77a93
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
42 changes: 34 additions & 8 deletions upload/fromurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,46 @@ func (d *fromURLData) wait() {
data,
)

if data.Status == uploadStatusError {
if len(d.err) < cap(d.err) {
d.err <- errors.New(data.Error)
switch data.Status {
case uploadStatusSuccess:
if data == nil || data.FileInfo == nil {
err := fmt.Errorf(
"no data received: %+v",
data,
)
log.Error(err)
if len(d.err) < cap(d.err) {
d.err <- err
}
return
}
d.done <- *data.FileInfo
return
}
if data.Status == uploadStatusInProgress {
case uploadStatusInProgress:
if len(d.progress) < cap(d.progress) {
d.progress <- data.Done
}
continue
case uploadStatusError:
if len(d.err) < cap(d.err) {
d.err <- errors.New(data.Error)
}
return
case uploadStatusWaiting:
log.Debugf(
"received status: %s, waiting",
data.Status,
)
default:
err := fmt.Sprintf(
"received status: %s, aborting",
data.Status,
)
log.Error(err)
if len(d.err) < cap(d.err) {
d.err <- errors.New(err)
}
return
}
d.done <- *data.FileInfo
return
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion upload/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
URLDuplicatesTrue = "1"
URLDuplicatesFalse = "0"

uploadStatuSuccess = "success"
uploadStatusSuccess = "success"
uploadStatusInProgress = "progress"
uploadStatusError = "error"
uploadStatusWaiting = "waiting"
Expand Down

0 comments on commit 5e77a93

Please sign in to comment.