Skip to content

Commit c7b9231

Browse files
committed
refactor to use the existing name required error in layer 1
Signed-off-by: RayyanSeliya <[email protected]>
1 parent 3eedefe commit c7b9231

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

cmd/delete.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,8 @@ No local files are deleted.
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040
// Layer 2: Catch technical errors and provide CLI-specific user-friendly messages
4141
err := runDelete(cmd, args, newClient)
42-
if err != nil && errors.Is(err, fn.ErrNameRequiredForDelete) {
43-
return fmt.Errorf(`%v
44-
45-
You can delete functions in two ways:
46-
47-
1. By name :
48-
func delete myfunction Delete function by name
49-
func delete myfunction --namespace apps Delete from specific namespace
50-
51-
2. By path :
52-
func delete --path /path/to/function Delete function at specific path
53-
54-
Examples:
55-
func delete myfunction Delete 'myfunction' from cluster
56-
func delete myfunction --namespace prod Delete from 'prod' namespace
57-
func delete --path ./myfunction Delete function at path
58-
59-
For more options, run 'func delete --help'`, err)
42+
if err != nil && errors.Is(err, fn.ErrNameRequired) {
43+
return formatDeleteNameRequiredError(err)
6044
}
6145
return err
6246
},
@@ -92,7 +76,7 @@ func runDelete(cmd *cobra.Command, args []string, newClient ClientFactory) (err
9276
}
9377
if !f.Initialized() {
9478
// Return technical error (Layer 1) - will be caught and enhanced by CLI
95-
return fn.ErrNameRequiredForDelete
79+
return fn.ErrNameRequired
9680
}
9781
}
9882

@@ -191,3 +175,27 @@ func (c deleteConfig) Prompt() (deleteConfig, error) {
191175

192176
return dc, err
193177
}
178+
179+
// formatDeleteNameRequiredError provides CLI-specific user-friendly error message
180+
// for delete command when function name is required
181+
func formatDeleteNameRequiredError(err error) error {
182+
return fmt.Errorf(`%v
183+
184+
Function name is required for deletion (or --path not specified).
185+
186+
You can delete functions in two ways:
187+
188+
1. By name :
189+
func delete myfunction Delete function by name
190+
func delete myfunction --namespace apps Delete from specific namespace
191+
192+
2. By path :
193+
func delete --path /path/to/function Delete function at specific path
194+
195+
Examples:
196+
func delete myfunction Delete 'myfunction' from cluster
197+
func delete myfunction --namespace prod Delete from 'prod' namespace
198+
func delete --path ./myfunction Delete function at path
199+
200+
For more options, run 'func delete --help'`, err)
201+
}

pkg/functions/errors.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ var (
2828
// eg "registry required". Then catch the error in the CLI and add the
2929
// cli-specific usage hints there
3030
ErrRegistryRequired = errors.New("registry required to build function, please set with `--registry` or the FUNC_REGISTRY environment variable")
31-
32-
// These are returned by core functions and caught by CLI for user-friendly messages
33-
ErrNameRequiredForDelete = errors.New("function name required for deletion")
3431
)
3532

3633
// ErrNotInitialized indicates that a function is uninitialized

0 commit comments

Comments
 (0)