Skip to content

Prompt cancellation exits 201 instead of documented 205 #3040

Closed

Description

@thesmart

Description

The cli docs under "Exit Codes" → "Task Errors" say:

**205** - Task cancelled by user

However this does not reproduce.

version: '3'
tasks:
  prompted:
    prompt: Continue?
    cmds:
      - echo done

Setup a harness to execute a task cancel:

import pty, os, time
pid, fd = pty.fork()
if pid == 0:
    os.execvp("task", ["task","prompted"])
else:
    time.sleep(0.5)
    os.write(fd, b"n\n")
    out=b""
    while True:
        try:
            d=os.read(fd,1024)
        except OSError:
            break
        if not d: break
        out+=d
    _,status=os.waitpid(pid,0)
    print(out.decode(errors="replace"))
    print("exit=", os.waitstatus_to_exitcode(status))

Run:

python3 pty_deny.py "$PWD"
Continue? [y/N]: n
task: Failed to run task "prompted": task: Task "prompted" cancelled by user

exit= 201

Actual result: exit 201
Expected result: exit 205


I have tested this on v3.48.0 and v3.53.1.

I looked into the code and found what I believe to be the defect.

TaskCancelledByUserError.Code() = CodeTaskCancelled (205), but task.go
(RunTask, identical in v3.48.0 and v3.53.0) wraps every body error in TaskRunError{...} whose
Code() = 201, and cmd/task/task.go resolves the exit code with a non-unwrapping type
assertion err.(errors.TaskError) — the inner 205 is shadowed on both versions.

Version

v3.53.0

Operating system

MacOS

Experiments Enabled

No response

Example Taskfile

version: '3'
tasks:
  prompted:
    prompt: Continue?
    cmds:
      - echo done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions