diff --git a/pkg/cmd/agent-task/create/create.go b/pkg/cmd/agent-task/create/create.go index a460a12e8..9c9b8ed68 100644 --- a/pkg/cmd/agent-task/create/create.go +++ b/pkg/cmd/agent-task/create/create.go @@ -70,6 +70,9 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co // Populate ProblemStatement from arg if len(args) > 0 { opts.ProblemStatement = args[0] + if strings.TrimSpace(opts.ProblemStatement) == "" { + return cmdutil.FlagErrorf("task description cannot be empty") + } } else if opts.ProblemStatementFile == "" && !opts.IO.CanPrompt() { return cmdutil.FlagErrorf("a task description or -F is required when running non-interactively") } diff --git a/pkg/cmd/agent-task/create/create_test.go b/pkg/cmd/agent-task/create/create_test.go index c96a2ef24..ef7f529ac 100644 --- a/pkg/cmd/agent-task/create/create_test.go +++ b/pkg/cmd/agent-task/create/create_test.go @@ -46,6 +46,21 @@ func TestNewCmdCreate(t *testing.T) { ProblemStatementFile: "", }, }, + { + name: "empty arg", + args: "''", + wantErr: "task description cannot be empty", + }, + { + name: "whitespace arg", + args: "' '", + wantErr: "task description cannot be empty", + }, + { + name: "whitespace and newline arg", + args: "'\n'", + wantErr: "task description cannot be empty", + }, { name: "mutually exclusive arg and file", args: "'some task inline' -F foo.md", @@ -96,7 +111,7 @@ func TestNewCmdCreate(t *testing.T) { _, err = cmd.ExecuteC() if tt.wantErr != "" { - require.Error(t, err, tt.wantErr) + require.EqualError(t, err, tt.wantErr) } else { require.NoError(t, err) }