Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Thor::Error instead of exit #2207

Merged
merged 2 commits into from
Feb 20, 2025
Merged

Raise Thor::Error instead of exit #2207

merged 2 commits into from
Feb 20, 2025

Conversation

KaanOzkan
Copy link
Contributor

Motivation

Exiting in add-on mode causes progress notifications to not be cleaned up

Implementation

Raise a Thor::Error instead. It's rescued by thor and we control its behaviour using exit_on_failure? here

Tests

@KaanOzkan KaanOzkan requested a review from a team as a code owner February 20, 2025 20:03
@KaanOzkan KaanOzkan added the enhancement New feature or request label Feb 20, 2025
@@ -131,15 +131,22 @@ def load_application

sig { returns(Tapioca::Dsl::Pipeline) }
def create_pipeline
error_handler = if @lsp_addon
->(error) {
say(error, :bold, :red)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an adjacent change to show errors in lsp output. say_error messages aren't visible in the logs, I assume due to stderr, but we'd like to have them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the styling symbols? I assume they do nothing in LSP mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

if errors.any?
errors.each do |msg|
report_error(msg)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given this usage I don't think we should raise inside report_error. We'll also be fixing a small bug.

@@ -78,6 +78,7 @@ def run(&blk)
No classes/modules can be matched for RBI generation.
Please check that the requested classes/modules include processable DSL methods.
ERROR
raise Thor::Error, ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
raise Thor::Error, ""
raise Thor::Error, "Exiting"

(or something like that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't know if we're exiting. I left it empty thinking that the error message above is sufficient. Do you think it's worth adding a secondary message?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, is the argument displayed to the user?

(not a blocker, I was suggesting it just to ease possible future troubleshooting. If we saw that without any backtrace then it could be pain to track where it came from).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's displayed without the stack trace: https://github.com/rails/thor/blob/3178667e1727504bf4fb693bf4ac74a5ca6c691e/lib/thor/base.rb#L586.

Right now we're getting an extra new line in the output due to this raise which isn't ideal 😬

`Thor::Error` is rescued by thor and we can control its behaviour using
`exit_on_failure?`
https://github.com/rails/thor/blob/3178667e1727504bf4fb693bf4ac74a5ca6c691e/lib/thor/base.rb#L587
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

I don't love that Tapioca internals know about Thor::Error, but we can refactor that later. For now, this should be fine to merge.

We now output an extra line due to the new raise. We can use an
`includes` check instead of `equals` to prevent the error in the future
@KaanOzkan
Copy link
Contributor Author

I don't love that Tapioca internals know about Thor::Error, but we can refactor that later. For now, this should be fine to merge.

I opened #2208, feel free to make suggestions in the issue

@KaanOzkan KaanOzkan added bugfix and removed enhancement New feature or request labels Feb 20, 2025
@KaanOzkan
Copy link
Contributor Author

KaanOzkan commented Feb 20, 2025

We have a CI failure due to Sorbet payload, it might be the github action cache or something is preventing bumping Sorbet in some workflows. I'm going to go ahead since this fix is time sensitive.

@KaanOzkan KaanOzkan merged commit e7641cf into main Feb 20, 2025
14 of 18 checks passed
@KaanOzkan KaanOzkan deleted the ko/addon-exit branch February 20, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants