Skip to content

Loading modules.json with the wrong encoding #218

Description

After installing Unity Editor 2019.4.15f1 with Unity Hub 2.4.2 on Japanese Windows 10 Pro 2004, Get-UnitySetupInstance complains with the following error:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-UnitySetupInstance
警告: ':' または '}' ではなく無効なオブジェクトが渡されました。 (7767): [{"id":"visualstudio","name":"Microsoft Visual Studio Community 2019","description":"Downloads and installs.... (snipped)

It orignates from this line:

$modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json

Get-Content -Raw loads modules.json with the wrong encoding which causes subsequent ConvertFrom-Json to fail:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-Content .\modules.json -Raw | ConvertFrom-Json
ConvertFrom-Json : ':' または '}' ではなく無効なオブジェクトが渡されました。 (7767): [{"id":"visualstudio","name":"Microsoft Visual Studio Community 2019","description":"Downloads and installs.... (snipped)

modules.json is actually in UTF-8 without BOM. Get-Content -Encoding UTF8 would workaround this case, but I'm not confident whether it's a correct fix:

PS C:\Program Files\Unity\Hub\Editor\2019.4.15f1> Get-Content .\modules.json -Encoding UTF8 | ConvertFrom-Json


id            : visualstudio
name          : Microsoft Visual Studio Community 2019
description   : Downloads and installs Microsoft Visual Studio Community 2019. By installing this you accept the license terms for Visual Studio.
downloadUrl   : https://go.microsoft.com/fwlink/?linkid=2086755
category      : Dev tools
installedSize : 1331200000
downloadSize  : 1363148800
visible       : True
selected      : False
cmd           : --productId "Microsoft.VisualStudio.Product.Community" --add "Microsoft.VisualStudio.Workload.ManagedGame" --add "Microsoft.VisualStudio.Workload.NativeDesktop" --add "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" --add "Microsoft.VisualStudio.Comp
                onent.Windows10SDK.16299.Desktop" --campaign "Unity3d_Unity" --passive --norestart --wait
eulaUrl1      : https://go.microsoft.com/fwlink/?linkid=2092534
eulaLabel1    : Visual Studio 2019 Community License Terms
eulaMessage   : Please review and accept the license terms before downloading and installing Microsoft Visual Studio.

...(snipped)...

id            : language-ja
name          : 日本語
description   : 日本語
downloadUrl   : https://new-translate.unity3d.jp/v1/live/54/2019.4/ja
category      : Language packs (Preview)
visible       : True
selected      : False
destination   : {UNITY_PATH}/Editor/Data/Localization
installedSize : 1739231
downloadSize  : 1739231

...(snipped)

It would be better to have a fall back path on modules.json parsing failures by adding a try-catch block.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions