Skip to content

Denote empty files in stack traces#473

Merged
cole-h merged 1 commit into
mainfrom
render-empty-files
May 26, 2026
Merged

Denote empty files in stack traces#473
cole-h merged 1 commit into
mainfrom
render-empty-files

Conversation

@edolstra

@edolstra edolstra commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Instead of

error: syntax error, unexpected end of file
 at «git+file:///.../nixos?rev=0defd19d32413f757d7273596cd9641cb91af25a&shallow=1&submodules=1»/configuration.nix:1:1:

(note the : followed by nothing at the end of the line), Nix now shows

error: syntax error, unexpected end of file
at «git+file:///home/eelco/Dev/nix-master/nixos?rev=0defd19d32413f757d7273596cd9641cb91af25a&shallow=1&submodules=1»/configuration.nix:1:1:
    1| (empty file)

Context

Summary by CodeRabbit

  • Bug Fixes
    • Improved error-message display when source code context is unavailable: shows a clear "(empty file)" placeholder instead of omitting the code line.
    • Refined error position formatting so the "at :" header appears only when code lines are present, ensuring more consistent and readable error reports.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ccafad9-5618-4fc1-a884-9b455f8687cc

📥 Commits

Reviewing files that changed from the base of the PR and between 5014f42 and 8a568b3.

📒 Files selected for processing (1)
  • src/libutil/error.cc

📝 Walkthrough

Walkthrough

Error formatting improvements in src/libutil/error.cc handle unavailable line-of-code data by printing an italic "(empty file)" placeholder and adjusting the position header punctuation. printCodeLines now emits the placeholder when no errLineOfCode exists; printPosMaybe caches pos->getCodeLines() and only prints the colon and code lines when available.

Changes

Error Output Formatting

Layer / File(s) Summary
Missing code line handling and header formatting
src/libutil/error.cc
printCodeLines adds an else branch that outputs an italic "(empty file)" placeholder when loc.errLineOfCode is absent. printPosMaybe caches pos->getCodeLines() once and appends : to the "at " header only when code lines are available, and uses the cached value to decide whether to print code lines.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A line that vanished from the file,
I print a gentle, italic smile—
"(empty file)" where nothing shows,
Now errors tell what no code knows.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Denote empty files in stack traces' clearly and concisely summarizes the main change: adding explicit notation for empty files in error stack traces instead of omitting them.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 render-empty-files

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/libutil/error.cc`:
- Around line 102-104: The else branch prints an "(empty file)" line but wrongly
dereferences the optional loc.errLineOfCode causing UB; update the formatting in
the else path (the block that writes to out using prefix, errPos.line and
*loc.errLineOfCode) to not dereference loc.errLineOfCode when has_value() is
false—use loc.errLineOfCode.value_or("") or pass an empty placeholder string (or
adjust the fmt call to omit that argument) so the output uses a safe empty
string instead of *loc.errLineOfCode.
🪄 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: c24a406c-4f9f-4bc2-8a06-04600aa80336

📥 Commits

Reviewing files that changed from the base of the PR and between 5d4c99f and 5014f42.

📒 Files selected for processing (1)
  • src/libutil/error.cc

Comment thread src/libutil/error.cc Outdated
@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request May 26, 2026 13:01 Inactive
@edolstra edolstra force-pushed the render-empty-files branch from 5014f42 to 8404436 Compare May 26, 2026 13:39
Instead of

  error: syntax error, unexpected end of file
  at «git+file:///.../nixos?rev=0defd19d32413f757d7273596cd9641cb91af25a&shallow=1&submodules=1»/configuration.nix:1:1:

Nix now shows

  error: syntax error, unexpected end of file
  at «git+file:///home/eelco/Dev/nix-master/nixos?rev=0defd19d32413f757d7273596cd9641cb91af25a&shallow=1&submodules=1»/configuration.nix:1:1:
      1| (empty file)
@edolstra edolstra force-pushed the render-empty-files branch from 8404436 to 8a568b3 Compare May 26, 2026 13:39
@github-actions github-actions Bot temporarily deployed to pull request May 26, 2026 13:45 Inactive
@cole-h cole-h added this pull request to the merge queue May 26, 2026
Merged via the queue into main with commit b93743b May 26, 2026
53 of 56 checks passed
@cole-h cole-h deleted the render-empty-files branch May 26, 2026 15:43
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