forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
127 lines (97 loc) · 3.64 KB
/
errors.go
File metadata and controls
127 lines (97 loc) · 3.64 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package cmd
import (
"fmt"
"strings"
)
// wrapNotInitializedError wraps an ErrNotInitialized error with CLI-specific guidance
func wrapNotInitializedError(err error, command string) error {
switch command {
case "build":
return fmt.Errorf(`%w
No function found in provided path (current directory or via --path).
You need to be in a function directory (or use --path).
Try this:
func create --language go myfunction Create a new function
cd myfunction Go into the function directory
func build --registry <registry> Build the function container
Or navigate to an existing function:
cd path/to/your/function
func build --registry <registry>
Or use --path flag:
func build --path /path/to/function --registry <registry>
For more options, run 'func build --help'`, err)
case "deploy":
return fmt.Errorf(`%w
No function found in provided path (current directory or via --path).
You need to be in a function directory (or use --path).
Try this:
func create --language go myfunction Create a new function
cd myfunction Go into the function directory
func deploy --registry <registry> Deploy to the cloud
Or navigate to an existing function:
cd path/to/your/function
func deploy --registry <registry>
Or use --path to deploy from anywhere:
func deploy --path /path/to/function --registry <registry>
For more options, run 'func deploy --help'`, err)
default:
return err
}
}
// wrapRegistryRequiredError wraps an ErrRegistryRequired error with CLI-specific guidance
func wrapRegistryRequiredError(err error, command string) error {
switch command {
case "build":
return fmt.Errorf(`%w
Try this:
func build --registry ghcr.io/myuser Build with registry
Or set the FUNC_REGISTRY environment variable:
export FUNC_REGISTRY=ghcr.io/myuser
func build
Common registries:
ghcr.io/myuser GitHub Container Registry
docker.io/myuser Docker Hub
quay.io/myuser Quay.io
Or specify full image name:
func build --image ghcr.io/myuser/myfunction:latest
For more options, run 'func build --help'`, err)
case "deploy":
return fmt.Errorf(`%w
Try this:
func deploy --registry ghcr.io/myuser
Or set the FUNC_REGISTRY environment variable:
export FUNC_REGISTRY=ghcr.io/myuser
func deploy
Common registries:
ghcr.io/myuser GitHub Container Registry
docker.io/myuser Docker Hub
quay.io/myuser Quay.io
For more options, run 'func deploy --help'`, err)
default:
return err
}
}
// wrapFlagParsingError adds DNS-1035 naming guidance to flag parsing errors
func wrapFlagParsingError(err error, suspectedName string) error {
return wrapFlagParsingErrorWithDetails(err, suspectedName, "", "")
}
// wrapFlagParsingErrorWithDetails adds DNS-1035 naming guidance with specific flag details
func wrapFlagParsingErrorWithDetails(err error, suspectedName, flagChar, parsedValue string) error {
var explanation string
if strings.HasPrefix(suspectedName, "--") {
explanation = fmt.Sprintf("It looks like '%s' was interpreted as a long flag.", suspectedName)
} else if len(suspectedName) > 1 && suspectedName[0] == '-' {
if flagChar != "" && parsedValue != "" {
explanation = fmt.Sprintf("It looks like '%s' was interpreted as the flag '-%s' with value '%s'.",
suspectedName, flagChar, parsedValue)
} else {
explanation = fmt.Sprintf("It looks like '%s' was interpreted as a flag.", suspectedName)
}
} else {
return err
}
return fmt.Errorf(`%v
Note: %s
Function names cannot start with hyphens per DNS-1035 naming rules.
Valid function names must start with a letter (a-z) and can contain letters, numbers, and hyphens`, err, explanation)
}