Skip to content

Display line diffs in dsl --verify error messages#2592

Open
dejmedus wants to merge 1 commit intomainfrom
jb-add-diff-output-to-error-msg
Open

Display line diffs in dsl --verify error messages#2592
dejmedus wants to merge 1 commit intomainfrom
jb-add-diff-output-to-error-msg

Conversation

@dejmedus
Copy link
Copy Markdown
Contributor

@dejmedus dejmedus commented Apr 10, 2026

Motivation

When tapioca dsl --verify detects out of date RBI files, the error message lists which files were added, removed, or changed. We could make it easier to visualize these changes by including the line diff output in the error message

Output example tapioca-verify-diff

Implementation

This PR diffs updated files against the originals during RBI verification and then includes the output in the error message when the diff is 250 lines or less, or whatever value is provided to --max-diff-lines flag

Tests

  • updated verify tests to include line diff
  • added a test for multi file changes and changes longer than max diff lines
  • added tests for diff behaviour

@dejmedus dejmedus added the enhancement New feature or request label Apr 10, 2026
@dejmedus dejmedus force-pushed the jb-add-diff-output-to-error-msg branch 3 times, most recently from f3c5b51 to 94ecc33 Compare April 21, 2026 19:31
@dejmedus dejmedus marked this pull request as ready for review April 21, 2026 20:46
@dejmedus dejmedus requested a review from a team as a code owner April 21, 2026 20:46
raise Tapioca::Error, <<~ERROR
file_diff = if diff_output.lines.count.between?(1, 250)
"#{set_color("Diff:", :red)}\n#{diff_output.chomp}"
end
Copy link
Copy Markdown
Contributor

@KaanOzkan KaanOzkan Apr 22, 2026

Choose a reason for hiding this comment

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

Do you think it's useful to output a message when the diff is longer than 250 lines and explain we're omitting it.

#{set_color("Reason:", :red)}
#{reasons}

#{file_diff}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should prevent this from printing a blank line if it's nil. You could prepend \n\n to file_diff above and then do #{reasons}#{file_diff}.

Another solution is doing 2 chomp calls. It might be better, I'm not sure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍🏼 I swapped chomp for rstrip

Comment thread lib/tapioca/commands/abstract_dsl.rb Outdated
end.join("\n")

raise Tapioca::Error, <<~ERROR
file_diff = if diff_output.lines.count.between?(1, 250)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this 250 limit be a CLI option instead and default to 250? dsl --verify --max-diff-lines=1000

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great idea 👌🏼

Comment thread lib/tapioca/commands/abstract_dsl.rb Outdated

stdout
rescue => e
say_error("Failed to create #{filename} diff. #{e.message}", :yellow)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you opt for yellow and not red? I think red is more consistent with rest of our errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked through say_error uses and it seemed like :yellow was used for warnings and :red for errors. I leaned towards this being a warning. Makes sense, changed to :red :)

Loading DSL extension classes... Done
Loading Rails application... Done
Loading DSL compiler classes... Done
Checking for out-of-date RBIs...
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you make this change to be more consistent with other tests? I assume it's not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was so I could assert stdout_equals rather than stdout_includes to ensure there isn't a stray Diff:

@command = DslVerify.new(
requested_constants: [],
requested_paths: [],
outpath: Pathname.new("tmp"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does DslVerify write something to the file system? I think other DslVerify tests run on a temporary directory that's cleaned up but this is not an integration test so it shouldn't use that, it's more costly.

If it is writing something we should clean up after, maybe we can create @tmp = Dir.mktmpdir in the before block, use that as the outpath and then clean it up in an after block.

Copy link
Copy Markdown
Contributor Author

@dejmedus dejmedus Apr 23, 2026

Choose a reason for hiding this comment

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

If im understanding correctly, outpath is required to create DslVerify but the command isn't being executed here, I just need an instance to pull file_diff from. I changed it to /dev/null to make it clearer that its unused. tbh I wouldn't be that against removing this test file if we don't find it helpful, file diff is being tested by verify tests also

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually ignore above, I moved out file_diff to rbi_files_helpers and the tests look much nicer now :)

@dejmedus dejmedus force-pushed the jb-add-diff-output-to-error-msg branch 2 times, most recently from 5e37dd0 to 0aa9400 Compare April 23, 2026 19:54
When `dsl --verify` detects out of date RBI files,
the error message lists which files were added,
removed, or changed. We could make it easier to
understand what has changed by including the line
diff output in the error message as well

This commit grabs the line diff output during RBI
verification and includes it in the error message
when the diff is 250 lines or less
@dejmedus dejmedus force-pushed the jb-add-diff-output-to-error-msg branch from 0aa9400 to 6bdba8a Compare April 24, 2026 21:11
@dejmedus dejmedus requested a review from KaanOzkan April 24, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants