Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Linux sudo raises UnexpectedExit instead of AuthFailure on incorrect password

Open
#918 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start with the Linux sudo path in invoke/context.py, especially _sudo, then trace the runner behavior named in invoke/runners.py through _finish. Compare the incorrect-password result with the macOS behavior; done means invoke.sudo raises AuthFailure rather than UnexpectedExit for the reported Linux case.

Written by the indexing model from the issue text.

Description

On Linux, invoke.sudo raises UnexpectedExit instead of AuthFailure on incorrect password.

>>> import invoke
>>> invoke.sudo("ls", password="a")
[sudo] password: Sorry, try again.
[sudo] password: Sorry, try again.
[sudo] password: sudo: 3 incorrect password attempts
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/__init__.py", line 68, in sudo
    return Context().sudo(command, **kwargs)
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/context.py", line 170, in sudo
    return self._sudo(runner, command, **kwargs)
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/context.py", line 215, in _sudo
    return runner.run(cmd_str, watchers=watchers, **kwargs)
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 376, in run
    return self._run_body(command, **kwargs)
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 432, in _run_body
    return self.make_promise() if self._asynchronous else self._finish()
  File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 499, in _finish
    raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: "sudo -S -p '[sudo] password: ' ls"

Exit code: 1

Stdout: already printed

Stderr: already printed

Version info

invoke: 2.0.0 (also tested on 1.7.1)
OS: Ubuntu 20.04.5 LTS
Python: 3.7.13 (also tested on 3.8.13 and 3.10.5)

I tested this on macOS and it raises AuthFailure as expected.

Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.