Skip to content

Conversation

@evgeni
Copy link
Member

@evgeni evgeni commented Aug 18, 2025

sometimes the collector gets called with :action => nil, e.g. when the originating request failed and Rails returned an error before identifying which action would have been executed.

this breaks the writer with the following error:

/home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:234:in `block in get_method_descriptions': undefined method `to_sym' for nil:NilClass (NoMethodError)
Did you mean?  to_m
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:233:in `map'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:233:in `get_method_descriptions'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/apipie_module.rb:34:in `method_missing'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:175:in `block (2 levels) in load_new_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:174:in `map'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:174:in `block in load_new_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `each'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `reduce'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `load_new_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:134:in `merge_old_new_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:77:in `write_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:81:in `write_examples'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:49:in `finish'
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:182:in `block in <top (required)>'
/home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/minitest-5.25.5/lib/minitest.rb:83:in `exit': exit (SystemExit)
	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/minitest-5.25.5/lib/minitest.rb:83:in `block (2 levels) in autorun'

While we could guard the writer from this problem, it doesn't really make sense to collect these calls anyway, as the data in there won't be usable.

@evgeni
Copy link
Member Author

evgeni commented Aug 18, 2025

One example is the base API controller in Foreman: https://github.com/theforeman/foreman/blob/fc4b4544804ced8cb52bfc40e9b54c092dedc698/app/controllers/api/base_controller.rb#L56-L61
And the test that submits bad JSON: https://github.com/theforeman/foreman/blob/fc4b4544804ced8cb52bfc40e9b54c092dedc698/test/integration/catch_json_parse_errors_test.rb#L5-L12

The resulting record looks like this:

{:controller=>Api::V2::HostsController, :action=>nil, :verb=>:POST, :path=>"/api/hosts", :params=>{}, :query=>nil, :request_data=>"{notAJson", :response_data=>{"status"=>400, "error"=>"There was a problem in the JSON you submitted: expected object key, got 'notAJson' at line 1 column 2"}, :code=>400}

@evgeni evgeni force-pushed the no-fail-for-me-apipie branch from caaab6c to b3a7e8d Compare August 18, 2025 14:17
@evgeni
Copy link
Member Author

evgeni commented Aug 18, 2025

the rubocop failures are unrelated, so are the Ruby 3.4 ones.

Copy link
Contributor

@PanosCodes PanosCodes left a comment

Choose a reason for hiding this comment

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

Nice, are there any another cases where the action might be nil? 🤔

@evgeni
Copy link
Member Author

evgeni commented Aug 18, 2025

I have (luckily?) not enough knowledge about Rails to answer this.

@ekohl
Copy link
Member

ekohl commented Aug 18, 2025

Code looks good, but on mobile and I'd like to have a closer look on my desktop

sometimes the collector gets called with `:action => nil`, e.g. when the
originating request failed and Rails returned an error *before*
identifying which action would have been executed.

this breaks the writer with the following error:

    /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:234:in `block in get_method_descriptions': undefined method `to_sym' for nil:NilClass (NoMethodError)
    Did you mean?  to_m
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:233:in `map'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/application.rb:233:in `get_method_descriptions'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/apipie_module.rb:34:in `method_missing'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:175:in `block (2 levels) in load_new_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:174:in `map'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:174:in `block in load_new_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `each'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `reduce'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:171:in `load_new_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:134:in `merge_old_new_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor/writer.rb:77:in `write_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:81:in `write_examples'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:49:in `finish'
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/apipie-rails-1.4.2/lib/apipie/extractor.rb:182:in `block in <top (required)>'
    /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/minitest-5.25.5/lib/minitest.rb:83:in `exit': exit (SystemExit)
    	from /home/runner/work/foreman/foreman/vendor/bundle/ruby/2.7.0/gems/minitest-5.25.5/lib/minitest.rb:83:in `block (2 levels) in autorun'

While we could guard the writer from this problem, it doesn't really
make sense to collect these calls anyway, as the data in there won't be
usable.
@evgeni evgeni force-pushed the no-fail-for-me-apipie branch from b3a7e8d to f7d8d88 Compare August 19, 2025 08:31
@ekohl ekohl merged commit 2a86a3a into Apipie:master Aug 19, 2025
31 of 32 checks passed
@ekohl ekohl added the bug label Aug 19, 2025
@evgeni evgeni deleted the no-fail-for-me-apipie branch August 19, 2025 09:15
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