Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'invalid char in json text' error #161

Merged
merged 1 commit into from
Jun 24, 2015

Conversation

zl4bv
Copy link
Contributor

@zl4bv zl4bv commented Jun 20, 2015

After further testing and closer inspection of the Chef logs, it seems my change in #134 introduced a different kind of error:

[2015-06-18T21:34:00+00:00] DEBUG: No data to collect for plugin Virtualization. Continuing...
[2015-06-18T21:34:00+00:00] DEBUG: No hints present for azure.
[2015-06-18T21:35:20+00:00] ERROR: Could not parse hint file at C:\chef\ohai\hints/ec2.json: lexical error: invalid char in json text.
                                       ÿþ
                     (right here) ------^

[2015-06-18T21:35:20+00:00] DEBUG: has_ec2_mac? == false
[2015-06-18T21:35:20+00:00] DEBUG: looks_like_ec2? == false

Apparently the method I used inserts a UTF-16 byte order mark.

The fix in this PR creates an empty file with no BOM.

@tyler-ball tyler-ball added this to the 0.10.0 milestone Jun 24, 2015
@tyler-ball tyler-ball self-assigned this Jun 24, 2015
@tyler-ball
Copy link
Contributor

Assigning to myself so we will review this during bug triage

@tyler-ball
Copy link
Contributor

@zl4bv Nice catch and thanks for the PR. I'm no Windows expert - will this work on Windows Server 2008? I'm guessing it more depends on the version of Powershell present?

@zl4bv
Copy link
Contributor Author

zl4bv commented Jun 24, 2015

As far as I know PowerShell has always used UTF-16 encoding (with BOM) as the default. This thread leads me to believe this has been the case since at least PowerShell 2.0.

When you call the New-Item PowerShell Cmdlet without the -Value flag I guess it doesn't try to write to the file and therefore doesn't apply any encoding. With $null >> it writes (nothing) to the file but it still sets the encoding by that action.

@zl4bv
Copy link
Contributor Author

zl4bv commented Jun 24, 2015

The New-Item Cmdlet was introduced in PowerShell 3.0 so it will work with Server 2008 and Server 2008 both as long as Service Pack 1 installed - which the images offered by Amazon do have installed.

@tyler-ball
Copy link
Contributor

I would like to get @smurawski's opinion, but I am 👍

@@ -427,7 +427,7 @@ def hostname(server, interface_type = nil)

def create_ec2_json(state)
if windows_os?
cmd = "mkdir \\etc\\chef\\ohai\\hints; echo $null >> \\etc\\chef\\ohai\\hints\\ec2.json"
cmd = "New-Item -Force C:\\chef\\ohai\\hints\\ec2.json -Type File"

Choose a reason for hiding this comment

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

The Type alias (for ItemType) wasn't introduced until PowerShell 3. Server 2008R2 ships with PS 2 by default and this will work fine if you change the parameter to -ItemType (which will be valid from PowerShell 1 and up)

@smurawski
Copy link

@zl4bv @tyler-ball I'd just make that one parameter name change and then I'm 👍

tyler-ball added a commit that referenced this pull request Jun 24, 2015
Fix 'invalid char in json text' error
@tyler-ball tyler-ball merged commit 9b9ec1d into test-kitchen:master Jun 24, 2015
@zl4bv
Copy link
Contributor Author

zl4bv commented Jun 24, 2015

Thanks for the suggestion @smurawski :)

Did you still want me to change the parameter name @tyler-ball?

@tyler-ball
Copy link
Contributor

@zl4bv I did it when I merged it - thanks for the initial contribution!

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.

None yet

3 participants