OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | |
9 "flag" | 8 "flag" |
10 "fmt" | 9 "fmt" |
11 "net/http" | 10 "net/http" |
12 "os" | 11 "os" |
13 "os/signal" | 12 "os/signal" |
14 "sort" | 13 "sort" |
15 "strings" | 14 "strings" |
16 "time" | 15 "time" |
17 | 16 |
18 "github.com/maruel/subcommands" | 17 "github.com/maruel/subcommands" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return nil | 209 return nil |
211 } | 210 } |
212 | 211 |
213 // logAnnotatedErr logs the full stack trace from an annotated error to the | 212 // logAnnotatedErr logs the full stack trace from an annotated error to the |
214 // installed logger at error level. | 213 // installed logger at error level. |
215 func logAnnotatedErr(ctx context.Context, err error, f string, args ...interface
{}) { | 214 func logAnnotatedErr(ctx context.Context, err error, f string, args ...interface
{}) { |
216 if err == nil { | 215 if err == nil { |
217 return | 216 return |
218 } | 217 } |
219 | 218 |
220 var buf bytes.Buffer | |
221 st := errors.RenderStack(err) | |
222 if _, derr := st.DumpTo(&buf); derr != nil { | |
223 // This can't really fail, since we're rendering to a Buffer. | |
224 panic(derr) | |
225 } | |
226 | |
227 nargs := make([]interface{}, len(args)+1) | 219 nargs := make([]interface{}, len(args)+1) |
228 » nargs[copy(nargs, args)] = buf.Bytes() | 220 » nargs[copy(nargs, args)] = strings.Join(errors.RenderStack(err), "\n") |
229 | 221 |
230 if f == "" { | 222 if f == "" { |
231 f = "Captured error stack:" | 223 f = "Captured error stack:" |
232 } | 224 } |
233 log.Errorf(ctx, f+"\n%s", nargs...) | 225 log.Errorf(ctx, f+"\n%s", nargs...) |
234 } | 226 } |
235 | 227 |
236 func mainImpl(ctx context.Context, defaultAuthOpts auth.Options, argv []string)
int { | 228 func mainImpl(ctx context.Context, defaultAuthOpts auth.Options, argv []string)
int { |
237 defaultAuthOpts.Scopes = allOutputScopes() | 229 defaultAuthOpts.Scopes = allOutputScopes() |
238 | 230 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 344 |
353 paniccatcher.Do(func() { | 345 paniccatcher.Do(func() { |
354 rc = mainImpl(ctx, chromeinfra.DefaultAuthOptions(), os.Args[1:]
) | 346 rc = mainImpl(ctx, chromeinfra.DefaultAuthOptions(), os.Args[1:]
) |
355 }, func(p *paniccatcher.Panic) { | 347 }, func(p *paniccatcher.Panic) { |
356 log.Fields{ | 348 log.Fields{ |
357 "panic.error": p.Reason, | 349 "panic.error": p.Reason, |
358 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) | 350 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) |
359 rc = runtimeErrorReturnCode | 351 rc = runtimeErrorReturnCode |
360 }) | 352 }) |
361 } | 353 } |
OLD | NEW |