Protecting against misuse of debug_output

Open
#326 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
networking

Research direction

Start at the net-protocol-0.2.2 Protocol#writing stack frame and trace the request through plugins/discourse-ai/lib/completions/endpoints/base.rb:129 and :158. Determine how @debug_output becomes a Hash and whether the initializer is the right boundary for validation. Done means the failure is prevented with a clear error and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

Failure/Error: @debug_output << '<- ' if @debug_output

NoMethodError:
  undefined method `<<' for an instance of Hash

/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:303:in `writing'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:286:in `write'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http/generic_request.rb:410:in `write_header'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http/generic_request.rb:264:in `send_request_with_body'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http/generic_request.rb:200:in `exec'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http.rb:2413:in `block in transport_request'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http.rb:2411:in `catch'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http.rb:2411:in `transport_request'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http.rb:2384:in `request'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/fakeweb-1.3.0/lib/fake_web/ext/net_http.rb:50:in `request_with_fakeweb'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/webmock-3.25.1/lib/webmock/http_lib_adapters/net_http.rb:108:in `block in request'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/webmock-3.25.1/lib/webmock/http_lib_adapters/net_http.rb:113:in `request'
./plugins/discourse-ai/lib/completions/endpoints/base.rb:158:in `block in perform_completion!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/webmock-3.25.1/lib/webmock/http_lib_adapters/net_http.rb:130:in `start_without_connect'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/webmock-3.25.1/lib/webmock/http_lib_adapters/net_http.rb:157:in `start'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-http-0.6.0/lib/net/http.rb:1070:in `start'
./plugins/discourse-ai/lib/completions/endpoints/base.rb:129:in `perform_completion!'
./plugins/discourse-ai/lib/completions/llm.rb:374:in `generate'

Not 100% sure, but worth opening this. Somehow fakeweb or webmock are initializing a protocol with an invalid object as @debug_output.

Clearly the fault is not here, but I wonder if we should add a simple check to the initializer?

raise ArgumentError, "debug_output must support <<" if @debug_output&.respond_to(:<<)
Dominant language
Ruby
Stars
148
Forks
95
Avg merge
10h 54m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/net-http

All issues in ruby/net-http

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.