-
Notifications
You must be signed in to change notification settings - Fork 25
/
errors.go
executable file
·45 lines (37 loc) · 1.34 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2015 Alex Browne. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
// File errors.go declares all the different errors that might be thrown
// by the package and provides constructors for each one.
package zoom
import "fmt"
// ModelNotFoundError is returned from Find and Query methods if a model
// that fits the given criteria is not found.
type ModelNotFoundError struct {
Collection *Collection
Msg string
}
func (e ModelNotFoundError) Error() string {
return "zoom: ModelNotFoundError: " + e.Msg
}
func newModelNotFoundError(mr *modelRef) error {
var msg string
if mr.model.ModelID() != "" {
msg = fmt.Sprintf("Could not find %s with id = %s", mr.spec.name, mr.model.ModelID())
} else {
msg = fmt.Sprintf("Could not find %s with the given criteria", mr.spec.name)
}
return ModelNotFoundError{
Collection: mr.collection,
Msg: msg,
}
}
// WatchError is returned whenever a watched key is modified before a
// transaction can execute. It is part of the implementation of optimistic
// locking in Zoom. You can watch a key with the Transaction.WatchKey method.
type WatchError struct {
keys []string
}
func (e WatchError) Error() string {
return fmt.Sprintf("zoom: watch error: at least one of the following keys has changed: %v", e.keys)
}