puppetlabs / puppetlabs/puppetlabs-stdlib

loadjson returns StringIO data which doesn't work in Puppet 8

Open
#1,414 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

community
Dominant language
Ruby
Stars
349
Forks
573
Avg merge
3d 3h
Merged PRs (30d)
1

Description

Describe the Bug

When using loadjson in a puppet manifest with small json files, the returning Data values come in as a StringIO instead of String value which Puppet 8 can't cast properly.

Expected Behavior

Return a hash of Strings.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use loadjson as documented to pull in a json file that you want to convert to hash.
  2. Run puppet agent and see the error.

Environment

  • RedHat Enterprise Linux 8
  • Puppet 8.3.0

Additional Context

I was able to fix this by editing the loadjson ruby code lines 56 and 63 changing from
JSON.parse(content) || args[1]
to
JSON.parse(content.string) || args[1]

Contributor guide

Open the contributing guide

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.

Research direction

Search the Ruby implementation of loadjson and inspect the code around lines 56 and 63, then reproduce the issue with Puppet 8.3.0 using a small JSON file. Done means loadjson returns a hash whose values are Strings and the Puppet agent no longer reports a casting error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.