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
fix: pouch pull image decode exception error #160
Conversation
We found this is your first time to contribute to Pouch, @HusterWan |
Thanks for your "PR", Reviewing.... |
the diff is okay to handle the errors. There are some designs that I want to discuss them with you.
|
@skoo87 Thanks for your opinion, i think all your points is reasonable, i will fix my code later |
ctrd/image.go
Outdated
@@ -160,7 +172,7 @@ outer: | |||
} | |||
// update status of active entries! | |||
for _, active := range active { | |||
progresses[active.Ref] = ProgressInfo{ | |||
progresses[active.Ref] = &ProgressInfo{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I do not like this block. It is so long and so hard to understand without annotations. Maybe in a follow-up, we need to refactor this a little bit to make this more readable.
@skoo87 I made a new PR, please review the code, if there has any problem, just ping me any time, thanks. |
cli/pull.go
Outdated
@@ -79,11 +80,16 @@ func renderOutput(responseBody io.ReadCloser) { | |||
fmt.Fprintf(os.Stderr, "failed to read the closing token: %v", err) | |||
return | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the blank line is superfluous.
cli/pull.go
Outdated
} | ||
|
||
func display(w io.Writer, statuses []ctrd.ProgressInfo, start time.Time) { | ||
var total int64 | ||
for _, status := range statuses { | ||
if len(status.ErrorMessage) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len(status.ErrorMessage) > 0 ===> status.ErrorMessage != ""
Using len(), We will think it's a slice array and so on.
ctrd/image.go
Outdated
Code: http.StatusInternalServerError, | ||
ErrorMessage: err.Error(), | ||
} | ||
msgList = append(msgList, errMsg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/msgList/messages/g , the variable name does not need to contain it's type.
Others, We can combine those codes into one line.
messages := []ProgressInfo{
{
Code: xxxx,
ErrorMessage: xxxx,
}
}
Please squash your commits into single one commit, thanks. @HusterWan |
7f237e9
to
accfc83
Compare
Updated, Please take another look. @skoo87 Thanks |
the "PR" is conflicting, please rebase it. @HusterWan |
Signed-off-by: 万仔仁 <zirenwan@gmail.com>
@skoo87 rebase done |
LGTM |
Signed-off-by: HusterWan zirenwan@gmail.com
1.Describe what this PR did
fix json decode error when pouch pull image error
2.Does this pull request fix one issue?
fixes #123 .
3.Describe how you did it
return error message through stream body when pouch pull image
4.Describe how to verify it
excute command line: pouch pull busybox, will print error information
pouch:
pouchd
5.Special notes for reviews
https://golang.org/pkg/net/http/#ResponseWriter
there is a goroutine to send downloading progress information to client when pouch pull image, so when goroutine call Write once, the http header code will be set 200, later call WriteHeader(500) will print error: call multi WriteHeader, and 500 will not send to client.
so we should not only use http code to judge if pull is ok, but contains error information in ProgressMessage, then client can deal with error information appropriately