fix(brew): handle root-owned config dir from sudo installs#288
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊❌ Patch coverage is 78.31%. Project has 3639 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 75.38% 75.35% -0.03%
==========================================
Files 115 115 —
Lines 14518 14760 +242
Branches 0 0 —
==========================================
+ Hits 10943 11121 +178
- Misses 3575 3639 +64
- Partials 0 0 —Generated by Codecov Action |
fd8a30e to
55e7118
Compare
55e7118 to
b965269
Compare
|
Addressed both review comments in b965269: Promise.allSettled in checkOwnership: Refactored to use Bun.$ in resolveUid: Replaced with |
b965269 to
165c919
Compare
165c919 to
c4d7ea1
Compare
|
Addressed all four review comments in c4d7ea1: Command injection in Ownership check wrong when running as Duplicated |
c4d7ea1 to
2a41fca
Compare
|
Addressed two more comments in 2a41fca:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
- Make all post-install setup steps non-fatal using a bestEffort() wrapper
so Homebrew's post_install never aborts on permission errors
- In tryRepairReadonly(), detect root-owned files (uid 0) and emit a
targeted message with the actual username instead of falling through
to the generic warning
- Add ownership detection and repair to `sentry cli fix`:
- Checks config dir / DB / WAL / SHM file ownership
- When run as root (sudo sentry cli fix), performs chown to transfer
ownership back to the real user (inferred from SUDO_USER env var)
- When not root, prints the exact sudo chown command to run
2a41fca to
620f800
Compare
|
Addressed two more comments in 620f800:
|
Problem
Two errors were reported during Homebrew post-install of v0.12.0:
SQLiteError: unable to open database file(SQLITE_CANTOPEN) — setup abortsWarning: read-only database+EPERMon zsh completions — setup abortsRoot cause:
sudo brew installcreates root-owned~/.sentry/and~/.local/share/zsh/files. The setup command had no error handling, so any failure aborted the entire post-install script and Homebrew showed a scary error even though the binary installed fine.The same root cause explains the recurring "attempt to write a readonly database" Sentry telemetry issues (8 issues, 19 events, 100% macOS). Moving the config directory would not help — the same permission problems would occur at any path if created by root. macOS TCC does not restrict
~/.sentry/.Changes
Non-fatal setup steps (
setup.ts)Added a
bestEffort()wrapper around each post-install configuration step. Permission failures now log a warning instead of aborting. The binary is already installed — these steps are nice-to-have side effects.Root-owned file detection in
tryRepairReadonly(telemetry.ts)Before attempting
chmod(which fails silently on root-owned files), now checksstat().uid. If the file is owned by root, emits a targeted actionable message with the actual username:Username is inferred from
SUDO_USER→USER→USERNAME→os.userInfo().Ownership repair in
sentry cli fix(fix.ts)sudo chown -R <user> <configDir>andsudo sentry cli fixinstructions, exits with code 1sudo sentry cli fix): resolves the real user's UID viaid -u <username>, then performschownto transfer ownership backFixes CLI-7Q, CLI-7K, CLI-6N, CLI-6D, CLI-4Z, CLI-51, CLI-4E, CLI-2E