OLD | NEW |
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 | 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 | 6 // upstream SDK errors. This exists so that users can depend solely on this |
7 // wrapper library without also needing to import the SDK. | 7 // wrapper library without also needing to import the SDK. |
8 // | 8 // |
9 // Format of the errors is Err<sub>Name, where <sub> is one of the 2/3-letter | 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 | 10 // All Caps subpackage codes (e.g. DS, TQ, MC, etc.). Name is the same as the |
(...skipping 28 matching lines...) Expand all Loading... |
39 ErrMCCASConflict = memcache.ErrCASConflict | 39 ErrMCCASConflict = memcache.ErrCASConflict |
40 ErrMCNoStats = memcache.ErrNoStats | 40 ErrMCNoStats = memcache.ErrNoStats |
41 ErrMCNotStored = memcache.ErrNotStored | 41 ErrMCNotStored = memcache.ErrNotStored |
42 ErrMCServerError = memcache.ErrServerError | 42 ErrMCServerError = memcache.ErrServerError |
43 | 43 |
44 ErrTQTaskAlreadyAdded = taskqueue.ErrTaskAlreadyAdded | 44 ErrTQTaskAlreadyAdded = taskqueue.ErrTaskAlreadyAdded |
45 ) | 45 ) |
46 | 46 |
47 /////////////////////////////// Supporting code //////////////////////////////// | 47 /////////////////////////////// Supporting code //////////////////////////////// |
48 | 48 |
| 49 // ErrDSFieldMismatch is returned when a field is to be loaded into a different |
| 50 // type than the one it was stored from, or when a field is missing or |
| 51 // unexported in the destination struct. |
| 52 // StructType is the type of the struct pointed to by the destination argument |
| 53 // passed to Get or to Iterator.Next. |
| 54 type ErrDSFieldMismatch struct { |
| 55 StructType reflect.Type |
| 56 FieldName string |
| 57 Reason string |
| 58 } |
| 59 |
| 60 func (e *ErrDSFieldMismatch) Error() string { |
| 61 return fmt.Sprintf("gae: cannot load field %q into a %q: %s", |
| 62 e.FieldName, e.StructType, e.Reason) |
| 63 } |
| 64 |
49 // MultiError is returned by batch operations when there are errors with | 65 // MultiError is returned by batch operations when there are errors with |
50 // particular elements. Errors will be in a one-to-one correspondence with | 66 // particular elements. Errors will be in a one-to-one correspondence with |
51 // the input elements; successful elements will have a nil entry. | 67 // the input elements; successful elements will have a nil entry. |
52 type MultiError []error | 68 type MultiError []error |
53 | 69 |
54 func (m MultiError) Error() string { | 70 func (m MultiError) Error() string { |
55 s, n := "", 0 | 71 s, n := "", 0 |
56 for _, e := range m { | 72 for _, e := range m { |
57 if e != nil { | 73 if e != nil { |
58 if n == 0 { | 74 if n == 0 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // we know that err already conforms to the error interface (or
the caller's | 116 // we know that err already conforms to the error interface (or
the caller's |
101 // method wouldn't compile), so check to see if the error's unde
rlying type | 117 // method wouldn't compile), so check to see if the error's unde
rlying type |
102 // looks like one of the special error types we implement. | 118 // looks like one of the special error types we implement. |
103 v := reflect.ValueOf(err) | 119 v := reflect.ValueOf(err) |
104 if v.Type().ConvertibleTo(multiErrorType) { | 120 if v.Type().ConvertibleTo(multiErrorType) { |
105 err = v.Convert(multiErrorType).Interface().(error) | 121 err = v.Convert(multiErrorType).Interface().(error) |
106 } | 122 } |
107 } | 123 } |
108 return err | 124 return err |
109 } | 125 } |
OLD | NEW |