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

[fastlane] Print better errors when exception occurring in Fastfile #21977

Merged
merged 2 commits into from Apr 17, 2024

Conversation

AliSoftware
Copy link
Contributor

@AliSoftware AliSoftware commented Apr 17, 2024

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.
  • I've added or updated relevant unit tests.

Motivation and Context

When there is an error in the Fastfile, the error printed out isn't always clear which line from the fastfile the error comes from.

  • This happened to me while I was starting to use the lane :foo do |readonly: true| keyword syntax to declare my lanes in my Fastfile (see Add support for keyword arguments for lanes in Ruby 3 #21587) and noticed that calling that lane with incorrect arguments didn't show me the call site that needed fixing, but instead the line where the method was declared.
    🖼️ e.g. Fastfile calling a lane named alpha_code_signing which ends up calling update_code_signing_enterprise(read_only: true, app_identifiers: APP_IDS) with wrong parameters, but logs doesn't show me that the problem is at the call site in the alpha_code_signing laneimage
  • This also happen if you have a syntax error when calling a lane or have a string in your code that doesn't correspond to a lane, variable or action
    🖼️ e.g. If I have a boum! in the code of one of my lane, it doesn't show me where in the Fastfile that boum! call isimage

Description

This PR improves the output of errors that happen when evaluating lanes in the Fastfile—be it ArgumentError for invalid lane parameters, invalid action names, etc—to print more code context, and print that context in more cases (e.g. even if the exception from the Fastfile evaluation is not at the top of the backtrace).

Now the error reporting looks like this:

🖼️ Calling another lane with wrong keyword argumentsimage
🖼️ Calling another Ruby function with wrong argumentsimage
🖼️ Calling a non-existing method from the Fastfileimage

Testing Steps

  • Write a dummy Fastfile in a test folder
lane :parent do |arg1: true|
  child(arg1: arg1, arg2: arg2)
end
lane :child do |arg1: true, arg2: 42|
  custom_func(arg1: arg1, arg2: arg2)
end
def custom_func(arg1:, arg2:)
  UI.message("arg1: #{arg1}, arg2: #{arg2}")
end
  • Create a Gemfile in that test folder pointing to this branch of fastlane, run bundle install
  • Run bundle exec fastlane parent and confirm that it works
  • Run bundle exec fastlane parent arg_1:oops and confirm that the error is logged with a nice backtrace pointing to the definition of lane :parent, and the full Ruby stacktrace isn't printed
  • Edit the Fastfile to introduce an error in the call site of child within the parent lane
  • Run bundle exec fastlane parent arg1:false and confirm that the error is logged with two nice backtraces pointing to the definition of lane :child then the erroneous call site of it within lane :parent
  • Test other similar cases by moving the syntax errors to other places in the Fastfile, like in the call to custom_func

Copy link
Contributor

@lucgrabowski lucgrabowski left a comment

Choose a reason for hiding this comment

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

This is a great enhancement 💯
I've run the change locally and played with the Fastfile example you left in testing steps.

(one small thing about testing steps: in child lane definition, it should be a pipe at the end lane :child do |arg1: true, arg2: 42|)

@AliSoftware AliSoftware merged commit df12128 into master Apr 17, 2024
7 checks passed
@AliSoftware AliSoftware deleted the pretty-error-invalid-lane-params branch April 17, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants