Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ func TestUsageErrors(t *testing.T) {
{"mutually exclusive targets", []string{"send", "-a", "http://x", "-e", "http://y", "hi"}},
{"malformed agent-card url", []string{"card", "get", "-a", "http://exa mple.com"}},
{"missing agent-card file", []string{"card", "get", "-a", "/no/such/card.json"}},
{"missing --file-part file", []string{"send", "-a", "http://x", "--file-part", "/no/such/file.txt"}},
}

for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion internal/clicfg/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"strings"

"github.com/a2aproject/a2a-cli/internal/clierr"
"github.com/joho/godotenv"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -83,7 +84,7 @@ func loadLocal(opts LoadOpts) (*loadedFile, error) {
if opts.ConfigPath != "" {
values, err := loadConfigFile(opts.ConfigPath)
if err != nil {
return nil, fmt.Errorf("reading --config %q: %w", opts.ConfigPath, err)
return nil, clierr.Usage(fmt.Sprintf("reading --config %q: %v", opts.ConfigPath, err))
}
return &loadedFile{path: opts.ConfigPath, values: values}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions internal/clicfg/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ package clicfg

import (
"bytes"
"errors"
"os"
"path/filepath"
"strings"
"testing"

"github.com/a2aproject/a2a-cli/internal/clierr"
)

func TestLoadStore(t *testing.T) {
Expand Down Expand Up @@ -217,6 +220,16 @@ func TestLoadStoreErrors(t *testing.T) {
}
}

func TestLoadMissingConfigIsUsageError(t *testing.T) {
t.Parallel()

_, err := Load(LoadOpts{ConfigPath: filepath.Join(t.TempDir(), "missing.yaml")})
var ce *clierr.Error
if !errors.As(err, &ce) || ce.Code != clierr.CodeUsage {
t.Fatalf("Load() error = %v, want a usage error", err)
}
}

func TestLoadWalksUpForLocalEnv(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 2 additions & 1 deletion internal/flagparse/parts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"strings"

"github.com/a2aproject/a2a-cli/internal/clierr"
"github.com/a2aproject/a2a-go/v2/a2a"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -118,7 +119,7 @@ func buildFilePart(ref, mediaType string) (*a2a.Part, error) {
path := strings.TrimPrefix(ref, "file://")
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("reading --file-part %q: %w", ref, err)
return nil, clierr.Usage(fmt.Sprintf("reading --file-part %q: %v", ref, err))
}
p := a2a.NewRawPart(data)
p.Filename = filepath.Base(path)
Expand Down
Loading