Skip to content

When a task outputs data that cannot be serialized to JSON the task will stacktrace #1759

@donoghuc

Description

@donoghuc

Describe the Bug

When a task result cannot be serialized to JSON in

bolt/lib/bolt/result.rb

Lines 141 to 143 in 6851fc8

def to_json(opts = nil)
status_hash.to_json(opts)
end
there is a stacktrace:

cas@cas-ThinkPad-T460p:~/working_dir/bolt/Boltdir/site/test/tasks$ bolt task run test::big -t localhost
Started on localhost...
<JSON::GeneratorError> source sequence is illegal/malformed utf-8
	/home/cas/working_dir/bolt/lib/bolt/result.rb:142:in `to_json'
	/home/cas/working_dir/bolt/lib/bolt/result.rb:142:in `to_json'
	/home/cas/working_dir/bolt/lib/bolt/executor.rb:237:in `with_node_logging'
	/home/cas/working_dir/bolt/lib/bolt/executor.rb:274:in `block (2 levels) in run_task'
	/home/cas/working_dir/bolt/lib/bolt/executor.rb:115:in `block (3 levels) in queue_execute'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:353:in `run_task'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:342:in `block (3 levels) in create_worker'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `loop'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `block (2 levels) in create_worker'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `catch'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `block in create_worker'
	/home/cas/working_dir/bolt/vendor/bundle/ruby/2.5.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
Finished on localhost:
Failed on 1 target: localhost
Ran on 1 target in 0.11 sec

It looks like the task spec suggests handling this specific case with a special error https://github.com/puppetlabs/puppet-specifications/tree/master/tasks#errors

Expected Behavior

Better description of error than a JSON serialization stack trace.

Metadata

Metadata

Assignees

Labels

BugBug reports and fixes.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions