danger-ruby-swiftformat icon indicating copy to clipboard operation
danger-ruby-swiftformat copied to clipboard

Error running SwiftFormat: Empty output.

Open ffittschen opened this issue 4 years ago • 2 comments

Hi 👋🏻 Lately, we are increasingly seeing the following error message when running SwiftFormat using this Danger plugin.

bundler: failed to load command: danger (/Users/ci/.rbenv/versions/2.7.2/bin/danger)
Danger::DSLError: 
[!] Invalid `Dangerfile` file: Error running SwiftFormat: Empty output.
 #  from Dangerfile:5
 #  -------------------------------------------
 #    swiftformat.exclude = %w(Carthage/** **/*.generated.swift xcodetemplates/**)
 >    swiftformat.check_format(fail_on_error: true)
 #  
 #  -------------------------------------------

  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-swiftformat-0.8.1/lib/swiftformat/swiftformat.rb:33:in `check_format'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-swiftformat-0.8.1/lib/swiftformat/plugin.rb:54:in `check_format'
  Dangerfile:5:in `eval_file'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:311:in `eval'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:204:in `block in parse'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:201:in `instance_eval'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:201:in `parse'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/dangerfile.rb:287:in `run'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/danger_core/executor.rb:29:in `run'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/lib/danger/commands/runner.rb:73:in `run'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
  /Users/ci/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/danger-8.2.2/bin/danger:5:in `<top (required)>'
  /Users/ci/.rbenv/versions/2.7.2/bin/danger:23:in `load'
  /Users/ci/.rbenv/versions/2.7.2/bin/danger:23:in `<top (required)>'
[!] The exception involves the following plugins:
 -  danger-swiftformat
Error: Process completed with exit code 1.

After investigating this error a bit, I'd like to understand why the error is raised in the case of:

  • swift files not empty
  • status is successful
  • stdout is empty
  • stderr is empty

Sadly I can't reproduce this case locally, as stderr is never empty for me, but I think we could handle this case more gracefully than raising an Error. The danger-ruby-swiftlint gem is handling this case by just returning an empty hash, i.e. no issues to report.

https://github.com/ashfurrow/danger-ruby-swiftlint/blob/master/lib/danger_plugin.rb#L167-L169

Do you think we could follow this approach?

ffittschen avatar Feb 11 '21 11:02 ffittschen

Hi,

First off, thank you for the detailed issue 👍

I agree with you: we should not fail builds if the output of the command is empty. If you're up for creating the PR, that would be great 😃 If not, let me know and I'll have a look in the coming days.

garriguv avatar Feb 16 '21 23:02 garriguv

Great, I'll create a PR in the coming days 🙂

ffittschen avatar Feb 21 '21 09:02 ffittschen