/
errors.go
74 lines (56 loc) · 1.88 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Copyright (C) 2022 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/fogfish/dynamo
//
package ddb
import (
"errors"
"fmt"
"github.com/fogfish/dynamo/v2"
"github.com/fogfish/faults"
)
const (
errInvalidConnectorURL = faults.Safe1[string]("invalid connector url %s")
errServiceIO = faults.Type("service i/o failed")
errInvalidKey = faults.Type("invalid key")
errInvalidEntity = faults.Type("invalid entity")
)
// NotFound is an error to handle unknown elements
func errNotFound(err error, key dynamo.Thing) error {
return ¬Found{err: err, Thing: key}
}
type notFound struct {
dynamo.Thing
err error
}
func (e *notFound) Error() string {
return fmt.Sprintf("Not Found (%s, %s)", e.HashKey(), e.SortKey())
}
func (e *notFound) Unwrap() error { return e.err }
func (e *notFound) NotFound() string { return e.HashKey().Safe() + " " + e.SortKey().Safe() }
// errPreConditionFailed
func errPreConditionFailed(err error, thing dynamo.Thing, conflict bool, gone bool) error {
return &preConditionFailed{Thing: thing, conflict: conflict, gone: gone, err: err}
}
type preConditionFailed struct {
dynamo.Thing
conflict bool
gone bool
err error
}
func (e *preConditionFailed) Error() string {
return fmt.Sprintf("Pre Condition Failed (%s, %s)", e.HashKey(), e.SortKey())
}
func (e *preConditionFailed) PreConditionFailed() bool { return true }
func (e *preConditionFailed) Conflict() bool { return e.conflict }
func (e *preConditionFailed) Gone() bool { return e.gone }
func (e *preConditionFailed) Unwrap() error { return e.err }
// recover AWS ErrorCode
func recoverConditionalCheckFailedException(err error) bool {
var e interface{ ErrorCode() string }
ok := errors.As(err, &e)
return ok && e.ErrorCode() == "ConditionalCheckFailedException"
}