| Index: vpython/application/support.go
|
| diff --git a/vpython/application/support.go b/vpython/application/support.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9ddca45c10501062924af41dd1af1f97b8359378
|
| --- /dev/null
|
| +++ b/vpython/application/support.go
|
| @@ -0,0 +1,39 @@
|
| +// Copyright 2017 The LUCI Authors. All rights reserved.
|
| +// Use of this source code is governed under the Apache License, Version 2.0
|
| +// that can be found in the LICENSE file.
|
| +
|
| +package application
|
| +
|
| +import (
|
| + "github.com/luci/luci-go/vpython/python"
|
| +
|
| + "github.com/luci/luci-go/common/errors"
|
| +
|
| + "golang.org/x/net/context"
|
| +)
|
| +
|
| +var appKey = "github.com/luci/luci-go/vpython/application.A"
|
| +
|
| +func withApplication(c context.Context, a *A) context.Context {
|
| + return context.WithValue(c, &appKey, a)
|
| +}
|
| +
|
| +func getApplication(c context.Context) *A {
|
| + return c.Value(&appKey).(*A)
|
| +}
|
| +
|
| +func run(c context.Context, fn func(context.Context) error) int {
|
| + err := fn(c)
|
| +
|
| + switch t := errors.Unwrap(err).(type) {
|
| + case nil:
|
| + return 0
|
| +
|
| + case python.Error:
|
| + return int(t)
|
| +
|
| + default:
|
| + errors.Log(c, err)
|
| + return 1
|
| + }
|
| +}
|
|
|