Skip to content

sentry: Log the Nix command / subcommand#436

Merged
edolstra merged 1 commit intomainfrom
sentry-log-command
Apr 23, 2026
Merged

sentry: Log the Nix command / subcommand#436
edolstra merged 1 commit intomainfrom
sentry-log-command

Conversation

@edolstra
Copy link
Copy Markdown
Collaborator

@edolstra edolstra commented Apr 23, 2026

Motivation

Improve Sentry crash reports.

Note: this only include the command/subcommand (e.g. nix flake update), but no other command-line arguments.

Context

Summary by CodeRabbit

  • Chores
    • Enhanced error-tracking so reports include the invoked command name.
    • Added subcommand path context to diagnostics so errors show the full nested command invoked.
    • Adjusted command-path collection to ensure subcommand context is captured consistently, improving issue visibility.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

Sentry initialization now sets a nix_command tag from the executable basename. Subcommand derivation from the CLI MultiCommand is moved to run before the helpRequested early return, and when Sentry is enabled a nix_subcommand tag is set with the space-separated subcommand path.

Changes

Cohort / File(s) Summary
Sentry Tagging & CLI ordering
src/nix/main.cc
Set nix_command (exec basename) during Sentry init; moved nested subcommand derivation earlier (before args.helpRequested) and removed prior help-scoped derivation; set nix_subcommand tag under HAVE_SENTRY with space-separated subcommand path.

Sequence Diagram(s)

(No sequence diagram generated — change is a localized reorder and tagging in a single source file.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • cole-h

Poem

🐰
I hopped through argv and found my trail,
Basename here, subcommands set like a sail.
Sentry listens with tags all neat,
Tracking each hop of my tiny feet. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: logging Nix command and subcommand information to Sentry for improved crash reporting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentry-log-command

Comment @coderabbitai help to get the list of available commands and usage tips.

@edolstra edolstra force-pushed the sentry-log-command branch from 7b7b077 to 2e25546 Compare April 23, 2026 17:25
@edolstra edolstra enabled auto-merge April 23, 2026 17:26
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/nix/main.cc`:
- Line 417: The sentry_set_tag call is tagging nix_command with argv[0] which
can be a full path and leak user-specific data; update the code in main (where
sentry_set_tag is called) to normalize argv[0] to the executable basename before
tagging (e.g., use std::filesystem::path(argc>0?argv[0]:"").filename().string()
or an equivalent basename/libgen approach) and pass that basename string into
sentry_set_tag instead of the raw argv[0].
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f580517-f889-44f9-b635-c0d4a2851e5e

📥 Commits

Reviewing files that changed from the base of the PR and between 0c00b00 and 2e25546.

📒 Files selected for processing (1)
  • src/nix/main.cc

Comment thread src/nix/main.cc Outdated
@github-actions github-actions Bot temporarily deployed to pull request April 23, 2026 17:34 Inactive
Note: this only include the command/subcommand (e.g. `nix flake
update`), but no other command-line arguments.
@edolstra edolstra force-pushed the sentry-log-command branch from 2e25546 to 6196dc2 Compare April 23, 2026 17:34
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/nix/main.cc (1)

573-581: Minor: Redundant null check for command.

The condition command && on line 576 is redundant since the while (command) loop condition on line 575 already guarantees command is non-null when entering the loop body.

Proposed simplification
 std::vector<std::string> subcommand;
 MultiCommand * command = &args;
 while (command) {
-    if (command && command->command) {
+    if (command->command) {
         subcommand.push_back(command->command->first);
         command = dynamic_cast<MultiCommand *>(&*command->command->second);
     } else
         break;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/nix/main.cc` around lines 573 - 581, The if condition inside the while
loop redundantly checks `command` even though the loop `while (command)` already
ensures it's non-null; update the loop body in function using `MultiCommand *
command = &args` to remove the redundant `command &&` and just test `if
(command->command)` (or equivalently `if (command->command) { ... } else
break;`) when pushing into `subcommand` and performing the `dynamic_cast` to the
next `MultiCommand`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/nix/main.cc`:
- Around line 573-581: The if condition inside the while loop redundantly checks
`command` even though the loop `while (command)` already ensures it's non-null;
update the loop body in function using `MultiCommand * command = &args` to
remove the redundant `command &&` and just test `if (command->command)` (or
equivalently `if (command->command) { ... } else break;`) when pushing into
`subcommand` and performing the `dynamic_cast` to the next `MultiCommand`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ccfe4473-9597-4763-8ad0-54f9fc994225

📥 Commits

Reviewing files that changed from the base of the PR and between 2e25546 and 6196dc2.

📒 Files selected for processing (1)
  • src/nix/main.cc

@github-actions github-actions Bot temporarily deployed to pull request April 23, 2026 17:39 Inactive
@edolstra edolstra added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit 6097560 Apr 23, 2026
31 checks passed
@edolstra edolstra deleted the sentry-log-command branch April 23, 2026 18:16
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.

2 participants