Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: upstream_errors.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « taskqueue_testable.go ('k') | upstream_types.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains types and values which are mirrors/duplicates of the
6 // upstream SDK errors. This exists so that users can depend solely on this
7 // wrapper library without also needing to import the SDK.
8 //
9 // Format of the errors is Err<sub>Name, where <sub> is one of the 2/3-letter
10 // All Caps subpackage codes (e.g. DS, TQ, MC, etc.). Name is the same as the
11 // original SDK error.
12 //
13 // Note that this only replicates the 'named' errors (which a user might compare
14 // for equality or observe by-type in their code like ErrDSNoSuchEntity). The
15 // underlying implementations can (and do) return many more sorts of non-named
16 // and custom errors.
17
18 package gae 5 package gae
19 6
20 import ( 7 import (
21 "fmt" 8 "fmt"
22 "reflect" 9 "reflect"
23 "sync" 10 "sync"
24
25 "google.golang.org/appengine/datastore"
26 "google.golang.org/appengine/memcache"
27 "google.golang.org/appengine/taskqueue"
28 ) 11 )
29 12
30 // These are pass-through versions from the managed-VM SDK. All implementations
31 // must return these (exact) errors (not just an error with the same text).
32 var (
33 ErrDSInvalidEntityType = datastore.ErrInvalidEntityType
34 ErrDSInvalidKey = datastore.ErrInvalidKey
35 ErrDSNoSuchEntity = datastore.ErrNoSuchEntity
36 ErrDSConcurrentTransaction = datastore.ErrConcurrentTransaction
37 ErrDSQueryDone = datastore.Done
38
39 ErrMCCacheMiss = memcache.ErrCacheMiss
40 ErrMCCASConflict = memcache.ErrCASConflict
41 ErrMCNoStats = memcache.ErrNoStats
42 ErrMCNotStored = memcache.ErrNotStored
43 ErrMCServerError = memcache.ErrServerError
44
45 ErrTQTaskAlreadyAdded = taskqueue.ErrTaskAlreadyAdded
46 )
47
48 /////////////////////////////// Supporting code ////////////////////////////////
49
50 // ErrDSFieldMismatch is returned when a field is to be loaded into a different
51 // type than the one it was stored from, or when a field is missing or
52 // unexported in the destination struct.
53 // StructType is the type of the struct pointed to by the destination argument
54 // passed to Get or to Iterator.Next.
55 type ErrDSFieldMismatch struct {
56 StructType reflect.Type
57 FieldName string
58 Reason string
59 }
60
61 func (e *ErrDSFieldMismatch) Error() string {
62 return fmt.Sprintf("gae: cannot load field %q into a %q: %s",
63 e.FieldName, e.StructType, e.Reason)
64 }
65
66 // MultiError is returned by batch operations when there are errors with 13 // MultiError is returned by batch operations when there are errors with
67 // particular elements. Errors will be in a one-to-one correspondence with 14 // particular elements. Errors will be in a one-to-one correspondence with
68 // the input elements; successful elements will have a nil entry. 15 // the input elements; successful elements will have a nil entry.
69 type MultiError []error 16 type MultiError []error
70 17
71 func (m MultiError) Error() string { 18 func (m MultiError) Error() string {
72 s, n := "", 0 19 s, n := "", 0
73 for _, e := range m { 20 for _, e := range m {
74 if e != nil { 21 if e != nil {
75 if n == 0 { 22 if n == 0 {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 101
155 // Get returns the MultiError, or nil, if no non-nil error was Assign'd. 102 // Get returns the MultiError, or nil, if no non-nil error was Assign'd.
156 func (e *LazyMultiError) Get() error { 103 func (e *LazyMultiError) Get() error {
157 e.Lock() 104 e.Lock()
158 defer e.Unlock() 105 defer e.Unlock()
159 if e.me == nil { 106 if e.me == nil {
160 return nil 107 return nil
161 } 108 }
162 return e.me 109 return e.me
163 } 110 }
OLDNEW
« no previous file with comments | « taskqueue_testable.go ('k') | upstream_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698