Skip to content

fix: use EAFP try/except for os.getegid/geteuid in stat() (issue #177)#179

Open
Quantum0uasar wants to merge 3 commits into
cloud-custodian:mainfrom
Quantum0uasar:patch-1
Open

fix: use EAFP try/except for os.getegid/geteuid in stat() (issue #177)#179
Quantum0uasar wants to merge 3 commits into
cloud-custodian:mainfrom
Quantum0uasar:patch-1

Conversation

@Quantum0uasar
Copy link
Copy Markdown
Collaborator

Replace LBYL platform check with EAFP try/except AttributeError pattern.

os.getegid() and os.geteuid() are unavailable on Windows and other non-POSIX platforms (e.g. WASI), raising AttributeError. Rather than checking the platform up front, wrap the assignments in a try/except block so group_access and user_access are simply omitted when the underlying OS calls are not available.

Closes #177

…d-custodian#177)

Replace LBYL platform check with EAFP try/except AttributeError pattern.

os.getegid() and os.geteuid() are unavailable on Windows and other
non-POSIX platforms (e.g. WASI), raising AttributeError. Rather than
checking the platform up front, wrap the assignments in a try/except
block so group_access and user_access are simply omitted when the
underlying OS calls are not available.

Closes cloud-custodian#177
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 24, 2026

CLA Not Signed

@Quantum0uasar
Copy link
Copy Markdown
Collaborator Author

@slott56 Hi! Would you be able to take a look when you get a chance? All CI checks are passing — just needs a review to merge. Happy to make any changes if needed.

@kapilt
Copy link
Copy Markdown
Collaborator

kapilt commented May 28, 2026

@Quantum0uasar
Copy link
Copy Markdown
Collaborator Author

Good catch on the EAFP refactor — the try/except AttributeError approach is definitely the right call here over platform string checking. A couple of notes:

  1. The data dict used inside the try block — make sure it's initialized before this block so the except: pass path still returns a valid (partial) map without the access keys. Looks correct from the diff but worth confirming in context.
  2. It might be worth a brief comment above the try block explaining why AttributeError is caught (i.e., non-POSIX platforms like Windows/WASI don't expose os.getegid/os.geteuid). Helps future readers avoid confusion.

Once the CLA is signed this should be good to go. Thanks for the contribution!

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.

The __main__.py module breaks under Windows

2 participants