| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package application |
| 6 |
| 7 import ( |
| 8 "github.com/luci/luci-go/vpython/python" |
| 9 |
| 10 "github.com/luci/luci-go/common/errors" |
| 11 |
| 12 "golang.org/x/net/context" |
| 13 ) |
| 14 |
| 15 var appKey = "github.com/luci/luci-go/vpython/application.A" |
| 16 |
| 17 func withApplication(c context.Context, a *A) context.Context { |
| 18 return context.WithValue(c, &appKey, a) |
| 19 } |
| 20 |
| 21 func getApplication(c context.Context) *A { |
| 22 return c.Value(&appKey).(*A) |
| 23 } |
| 24 |
| 25 func run(c context.Context, fn func(context.Context) error) int { |
| 26 err := fn(c) |
| 27 |
| 28 switch t := errors.Unwrap(err).(type) { |
| 29 case nil: |
| 30 return 0 |
| 31 |
| 32 case python.Error: |
| 33 return int(t) |
| 34 |
| 35 default: |
| 36 errors.Log(c, err) |
| 37 return 1 |
| 38 } |
| 39 } |
| OLD | NEW |