-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrer.go
46 lines (38 loc) · 1.57 KB
/
errer.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
/*
Copyright 2025 Steven Dee
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package memoize
// Errer receives non-fatal errors that can occur in the memoization logic but
// that do not affect function outputs. It does not receive [ErrCacheMiss] or
// [ErrNotStored], but otherwise if anything goes wrong with cache retreival
// or storage, or with proto serialization or deserialization, it will be
// reported for either recovery or logging.
type Errer interface {
Error(error)
}
// ErrFunc is an interface wrapper for functions allowing them to be used as an
// [Errer].
type ErrFunc func(error)
// Error implements [Errer] for [ErrFunc].
func (f ErrFunc) Error(err error) {
f(err)
}
// ErrorHandler is the default Errer for the memoize package. It is nil by
// default. If it is set to non-nil, and there is not a custom [Errer]
// configured for a given [Memoizer], then it will receive all non-fatal
// errors. E.g. it may make sense to wire this up to a custom log.Errorf
// function, or even simply:
//
// memoize.ErrorHandler = func(err error) {
// log.Printf("ERROR: %v", err)
// }
var ErrorHandler Errer