Closed DrMurx closed 6 years ago
Thanks for your contribution to Sensu plugins! Without people like you submitting PRs we couldn't run the project. I will review it shortly.
Providing testing artifacts isn't easy here as the causing condition can't be reproduced reliably.
This is the error I receive and which I tried to fix:
Check failed to run: undefined method `gsub' for nil:NilClass, [
"/usr/local/bundle/bin/check-container-logs.rb:143:in `block in remove_headers'",
"/usr/local/bundle/bin/check-container-logs.rb:139:in `map!'",
"/usr/local/bundle/bin/check-container-logs.rb:139:in `remove_headers'",
"/usr/local/bundle/bin/check-container-logs.rb:134:in `process_docker_logs'",
"/usr/local/bundle/bin/check-container-logs.rb:188:in `block in run'",
"/usr/local/bundle/bin/check-container-logs.rb:187:in `each'",
"/usr/local/bundle/bin/check-container-logs.rb:187:in `run'",
"/usr/local/bundle/gems/sensu-plugin-2.5.0/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"
]
This is clearly because Ruby's string slice methods (in this case byteslice
) return nil
if the slice attempt is outside the string boundaries.
Pull Request Checklist
General
[x] Update Changelog following the conventions laid out on Our CHANGELOG Guidelines
[ ] ~Update README with any necessary configuration snippets~
[ ] ~Binstubs are created if needed~
[ ] ~RuboCop passes~
[ ] ~Existing tests pass~
Purpose
When chopping the binary headers from docker log response, empty log lines lead to a
nil.gsub
due to howString::byteslice
works. This PR filters that condition properly.