Skip to content

Commit 321f4b3

Browse files
dilyevskyclaude
andcommitted
[cli] rewrite API not-found errors to use user-facing names
When NameTransform is set, API errors leak the internal metadata name (e.g. "up-hyena-l2q.d.edge.fun--ips"). Wrap not-found errors in get and delete commands to show the original user argument instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d7e0ad8 commit 321f4b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/cmd/resource/builder.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/spf13/cobra"
9+
apierrors "k8s.io/apimachinery/pkg/api/errors"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/runtime"
1112
"k8s.io/apimachinery/pkg/types"
@@ -224,6 +225,9 @@ func (r *ResourceCommand[T, TList]) Build() *cobra.Command {
224225
}
225226
obj, err := r.ClientFunc(c).Get(cmd.Context(), name, metav1.GetOptions{})
226227
if err != nil {
228+
if r.NameTransform != nil && apierrors.IsNotFound(err) {
229+
return fmt.Errorf("%s %q not found", r.KindName, args[0])
230+
}
227231
return err
228232
}
229233
if err := r.printObj(cmd.Context(), obj, false, outputFormat); err != nil {
@@ -326,6 +330,9 @@ func (r *ResourceCommand[T, TList]) Build() *cobra.Command {
326330
}
327331
}
328332
if err = r.ClientFunc(c).Delete(cmd.Context(), name, metav1.DeleteOptions{}); err != nil {
333+
if r.NameTransform != nil && apierrors.IsNotFound(err) {
334+
return fmt.Errorf("%s %q not found", r.KindName, arg)
335+
}
329336
return err
330337
}
331338
fmt.Printf("%s %q deleted\n", r.KindName, arg)

0 commit comments

Comments
 (0)