-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
56 lines (47 loc) · 1.68 KB
/
Copy patherrors.go
File metadata and controls
56 lines (47 loc) · 1.68 KB
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
package ctapkit
import (
"context"
"errors"
"io/fs"
"github.com/go-ctap/kit/internal/ctaperrors"
"github.com/go-ctap/kit/internal/device"
"github.com/go-ctap/kit/model"
appconfig "github.com/go-ctap/kit/model/config"
"github.com/go-ctap/kit/transport"
)
func runtimeDeviceError(err error) error {
switch {
case errors.Is(err, device.ErrBusy):
return model.NewRuntimeError(model.ErrorBusy, err.Error(), err)
case errors.Is(err, device.ErrSelectionRequired):
return model.NewRuntimeError(model.ErrorInvalidOperation, err.Error(), err)
case errors.Is(err, device.ErrUnavailable):
return model.NewRuntimeError(model.ErrorInvalidState, err.Error(), err)
case errors.Is(err, transport.ErrPermissionDenied), errors.Is(err, fs.ErrPermission):
return model.NewRuntimeError(model.ErrorPermissionDenied, err.Error(), err)
case errors.Is(err, transport.ErrUnsupportedMode):
return model.NewRuntimeError(model.ErrorUnsupported, err.Error(), err)
case errors.Is(err, transport.ErrProxyUnavailable):
return model.NewRuntimeError(model.ErrorTransportFailure, err.Error(), err)
default:
return err
}
}
func normalizeRunError(err error) error {
if err == nil {
return nil
}
if model.IsErrorCategory(err, model.ErrorCanceled) {
return err
}
if errors.Is(err, context.Canceled) {
return model.NewRuntimeError(model.ErrorCanceled, "operation canceled", err)
}
if errors.Is(err, context.DeadlineExceeded) {
return model.NewRuntimeError(model.ErrorCanceled, "operation canceled", err)
}
return ctaperrors.Normalize(err)
}
func runtimePINRequiredError(label string) error {
return model.NewRuntimeError(model.ErrorInvalidOperation, label+" is required", appconfig.ErrPINRequired)
}