Skip to content

Catch getpwuid() KeyError on an unknown user id#1572

Merged
rolandwalker merged 1 commit intomainfrom
RW/catch-keyerror-on-getpwuid
Feb 16, 2026
Merged

Catch getpwuid() KeyError on an unknown user id#1572
rolandwalker merged 1 commit intomainfrom
RW/catch-keyerror-on-getpwuid

Conversation

@rolandwalker
Copy link
Copy Markdown
Contributor

@rolandwalker rolandwalker commented Feb 16, 2026

Description

Fixes #1567, if KeyError is the correct exception.

This can happen in the Docker context.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 16, 2026
@github-actions
Copy link
Copy Markdown

Findings

  1. Low: fallback hides the actual UID, which could make debugging harder. Consider including the numeric UID in the message, e.g. '<unknown (uid=12345)>', so operators can diagnose mismatched NSS/LDAP. This is in mycli/main.py:726.
  2. Low: missing test coverage for getpwuid() raising KeyError. A regression test around socket connection logging would validate the behavior. This relates to mycli/main.py:724.

No security concerns found.

If you want, I can sketch a minimal test case for the KeyError branch.

Copy link
Copy Markdown
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to test the bots suggestion, you can change the owner of the socket and try.

sudo chown 323:323 /var/run/mysqld/mysqld.sock

Error should look something like this anyway:

'getpwuid(): uid not found: 323'

@rolandwalker
Copy link
Copy Markdown
Contributor Author

It seems KeyError is right. The bot suggestions don't seem overly interesting. This is solely for logging.

@rolandwalker rolandwalker merged commit d8530f8 into main Feb 16, 2026
10 checks passed
@rolandwalker rolandwalker deleted the RW/catch-keyerror-on-getpwuid branch February 16, 2026 18:51
@scottnemes
Copy link
Copy Markdown
Contributor

It seems KeyError is right. The bot suggestions don't seem overly interesting. This is solely for logging.

Yes, point was you could get the uid from the exception to display as the owner if you wanted. But sounds like you in fact do not want, so doesn't matter hah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crashing with unknown uid

2 participants