-
Notifications
You must be signed in to change notification settings - Fork 311
/
errors.go
73 lines (57 loc) · 2.68 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
// Copyright 2020 The Okteto Authors
// 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 errors
import (
"errors"
"fmt"
"strings"
)
// UserError is meant for errors displayed to the user. It can include a message and a hint
type UserError struct {
E error
Hint string
}
// Error returns the error message
func (u UserError) Error() string {
return u.E.Error()
}
var (
// ErrNotDevDeployment is raised when we detect that the deployment was returned to production mode
ErrNotDevDeployment = errors.New("Deployment is no longer in developer mode")
// ErrCommandFailed is raised when the command execution failed
ErrCommandFailed = errors.New("Command execution failed")
// ErrNotLogged is raised when we can't get the user token
ErrNotLogged = fmt.Errorf("please run 'okteto login [URL]' and try again")
// ErrNotFound is raised when an object is not found
ErrNotFound = fmt.Errorf("not found")
// ErrInternalServerError is raised when an internal server error or similar is received
ErrInternalServerError = fmt.Errorf("internal server error, please try again")
// ErrQuota is returned when there aren't enough resources to enable dev mode
ErrQuota = fmt.Errorf("Quota exceeded, please free some resources and try again")
// ErrUnknownSyncError is returned when syncthing reports an unknown sync error
ErrUnknownSyncError = fmt.Errorf("Unknown syncthing error")
// ErrNotInDevContainer is returned when an unsupported command is invoked from a dev container (e.g. okteto up)
ErrNotInDevContainer = fmt.Errorf("this command is not supported from inside an development container")
// ErrLostSyncthing is raised when we lose connectivity with syncthing
ErrLostSyncthing = fmt.Errorf("synchronization service unresponsive")
// ErrNotInDevMode is raised when the eployment is not in dev mode
ErrNotInDevMode = fmt.Errorf("Deployment is not in development mode anymore")
)
// IsNotFound returns true if err is of the type not found
func IsNotFound(err error) bool {
return err != nil && strings.Contains(err.Error(), "not found")
}
// IsNotExist returns true if err is of the type does not exist
func IsNotExist(err error) bool {
return err != nil && strings.Contains(err.Error(), "does not exist")
}