Merge pull request #7279 from tstromberg/unable-err

Improve display of host startup errors
pull/7345/head
Thomas Strömberg 2020-04-01 14:29:52 -07:00 committed by GitHub
commit 62adc6761d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -61,16 +61,16 @@ func WithCodeT(code int, format string, a ...out.V) {
func WithError(msg string, err error) { func WithError(msg string, err error) {
p := problem.FromError(err, runtime.GOOS) p := problem.FromError(err, runtime.GOOS)
if p != nil { if p != nil {
WithProblem(msg, p) WithProblem(msg, err, p)
} }
displayError(msg, err) displayError(msg, err)
os.Exit(Software) os.Exit(Software)
} }
// WithProblem outputs info related to a known problem and exits. // WithProblem outputs info related to a known problem and exits.
func WithProblem(msg string, p *problem.Problem) { func WithProblem(msg string, err error, p *problem.Problem) {
out.ErrT(out.Empty, "") out.ErrT(out.Empty, "")
out.FatalT(msg) out.ErrT(out.FailureType, "[{{.id}}] {{.msg}} {{.error}}", out.V{"msg": msg, "id": p.ID, "error": p.Err})
p.Display() p.Display()
if p.ShowIssueLink { if p.ShowIssueLink {
out.ErrT(out.Empty, "") out.ErrT(out.Empty, "")

View File

@ -351,10 +351,7 @@ func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*hos
return host, exists return host, exists
} }
out.T(out.FailureType, "StartHost failed again: {{.error}}", out.V{"error": err}) // Don't use host.Driver to avoid nil pointer deref
out.T(out.Workaround, `Run: "{{.delete}}", then "{{.start}} --alsologtostderr -v=1" to try again with more logging`,
out.V{"delete": mustload.ExampleCmd(cc.Name, "delete"), "start": mustload.ExampleCmd(cc.Name, "start")})
drv := cc.Driver drv := cc.Driver
exit.WithError(fmt.Sprintf(`Failed to start %s %s. "%s" may fix it.`, drv, driver.MachineType(drv), mustload.ExampleCmd(cc.Name, "start")), err) exit.WithError(fmt.Sprintf(`Failed to start %s %s. "%s" may fix it.`, drv, driver.MachineType(drv), mustload.ExampleCmd(cc.Name, "start")), err)
return host, exists return host, exists

View File

@ -57,7 +57,6 @@ type match struct {
// Display problem metadata to the console // Display problem metadata to the console
func (p *Problem) Display() { func (p *Problem) Display() {
out.ErrT(out.FailureType, "Error: [{{.id}}] {{.error}}", out.V{"id": p.ID, "error": p.Err})
out.ErrT(out.Tip, "Suggestion: {{.advice}}", out.V{"advice": translate.T(p.Advice)}) out.ErrT(out.Tip, "Suggestion: {{.advice}}", out.V{"advice": translate.T(p.Advice)})
if p.URL != "" { if p.URL != "" {
out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": p.URL}) out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": p.URL})
@ -65,6 +64,12 @@ func (p *Problem) Display() {
if len(p.Issues) == 0 { if len(p.Issues) == 0 {
return return
} }
if len(p.Issues) == 1 {
out.ErrT(out.Issues, "Related issue: {{.url}}", out.V{"url": fmt.Sprintf("%s/%d", issueBase, p.Issues[0])})
return
}
out.ErrT(out.Issues, "Related issues:") out.ErrT(out.Issues, "Related issues:")
issues := p.Issues issues := p.Issues
if len(issues) > 3 { if len(issues) > 3 {

View File

@ -44,7 +44,6 @@ func TestDisplay(t *testing.T) {
problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test")}, problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test")},
description: "url, id and err", description: "url, id and err",
expected: ` expected: `
* Error: [example] test
* Suggestion: * Suggestion:
* Documentation: example.com * Documentation: example.com
`, `,
@ -53,7 +52,6 @@ func TestDisplay(t *testing.T) {
problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1}, Advice: "you need a hug"}, problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1}, Advice: "you need a hug"},
description: "with 2 issues and suggestion", description: "with 2 issues and suggestion",
expected: ` expected: `
* Error: [example] test
* Suggestion: you need a hug * Suggestion: you need a hug
* Documentation: example.com * Documentation: example.com
* Related issues: * Related issues:
@ -65,7 +63,6 @@ func TestDisplay(t *testing.T) {
problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1}}, problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1}},
description: "with 2 issues", description: "with 2 issues",
expected: ` expected: `
* Error: [example] test
* Suggestion: * Suggestion:
* Documentation: example.com * Documentation: example.com
* Related issues: * Related issues:
@ -78,7 +75,6 @@ func TestDisplay(t *testing.T) {
problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1, 2, 3, 4, 5}}, problem: Problem{ID: "example", URL: "example.com", Err: fmt.Errorf("test"), Issues: []int{0, 1, 2, 3, 4, 5}},
description: "with 6 issues", description: "with 6 issues",
expected: ` expected: `
* Error: [example] test
* Suggestion: * Suggestion:
* Documentation: example.com * Documentation: example.com
* Related issues: * Related issues: