fix(config): fall back to "user" when os.userInfo() is unavailable#1129
Conversation
|
Warning Review limit reached
More reviews will be available in 54 minutes and 38 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR adds error handling for system username retrieval in two configuration modules. Both ChangesUsername Resilience
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request prevents configuration load crashes on minimal hosts (such as certain containers) where os.userInfo() throws an error due to a missing passwd entry. It wraps os.userInfo() calls in try-catch blocks in both the configuration loader and the macOS-specific managed preferences reader, falling back to a default username. A regression test has also been added. The reviewer suggests improving the fallback mechanism by checking environment variables like process.env.USER or process.env.USERNAME before defaulting to the hardcoded 'user', which is particularly critical on macOS to avoid breaking managed preferences path lookups.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
os.userInfo() throws a SystemError on minimal hosts with no matching passwd entry (some containers, locked-down accounts). Both config load (config.ts) and the macOS managed-preferences lookup (managed.ts) called it unguarded, so a process that started without a resolvable system user crashed during config load. Guard both call sites with try/catch and fall back to the generic "user", also coercing an empty username to "user". Add regression tests: config load resolves username to "user" when os.userInfo() throws, and readManagedPreferences() (darwin branch) does not throw under the same failure. Reimplemented for PawWork from upstream anomalyco/opencode b5632ea700 (PR #29332, thanks Shoubhit Dash); the fork has no common ancestor so this is an adapted port, not a cherry-pick.
666fa9f to
9206bca
Compare
Summary
os.userInfo()throws aSystemErroron minimal hosts that have no matching passwd entry (some containers, locked-down service accounts). Two config-load call sites called it unguarded, so a process started without a resolvable system user crashed during config load. This guards both withtry/catch, falls back to the generic"user", and also coerces an empty username to"user".Why
packages/opencode/src/config/config.ts:1082—if (!result.username) result.username = os.userInfo().username(unguarded; runs on every platform).packages/opencode/src/config/managed.ts:58—const user = os.userInfo().username(unguarded; macOS managed-preferences lookup).Either throw aborts config load with an unhandled
SystemError. The system username is a convenience default, not a hard requirement, so an unavailable user should degrade to a generic value rather than crash startup.Related Issue
No PawWork issue. Reimplemented for PawWork from upstream
anomalyco/opencodeb5632ea700(PR #29332, thanks Shoubhit Dash). The fork has no common ancestor with upstream, so this is an adapted port, not a cherry-pick.Human Review Status
Pending
Review Focus
The two guards mirror upstream exactly. The
config.tsguard is cross-platform; themanaged.tsguard is darwin-only (readManagedPreferencesreturns early off macOS). Confirm the fallback value"user"is acceptable for both the config username default and the macOS managed-preferences path lookup.Risk Notes
Low. Behavior changes only when
os.userInfo()throws or returns an empty username (previously a crash). No platform/packaging/UI surface touched. Bothlogandoswere already in scope at both sites.How To Verify
Screenshots or Recordings
N/A — no visible UI change.
Checklist
bug,enhancement,task,documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.app,ui,platform,harness,ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.P0,P1,P2,P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.Pending,Approved by @<reviewer>, orNot required: <reason>(default isPending; "not required" is restricted to bot-authored low-risk PRs).dev, and my PR title and commit messages use Conventional Commits in English.Summary by CodeRabbit
Bug Fixes