Azure-Player / azure.datafactory.tools

Tools for deploying Data Factory (v2) in Microsoft Azure
https://azureplayer.net/adftools
MIT License
217 stars 69 forks source link

##[error]Invalid JSON primitive: . (when run under PS 5.1) #425

Open NowinskiK opened 5 days ago

NowinskiK commented 5 days ago

Describe the bug When a deployment is run for the second time, the process of converting from String to JSON of Deployment State File fails.

To Reproduce Set up Storage URI to enable Incremental Deployment using Storage Account for State. The first deployment is successful, but the second fails.

Expected behaviour The process will convert JSON (UTF-8) successfully and use deployment state body to establish which objects can be skipped during the deployment.

LOG

Ready to read file from storage: https://sqlplayer2020.blob.core.windows.net/adftools/SQLPlayerDemo-UAT.adftools_deployment_state.json
##[debug]Leaving D:\a\_tasks\PublishADFTask_b2032481-f9a9-476d-af8f-9156ee066e1b\2.0.1590\PublishADF.ps1.
##[debug]Trying to disconnect from Azure and clear context at process scope
##[debug]Cannot verify the Microsoft .NET Framework version 4.7.2 because it is not included in the list of permitted versions.
##[debug]Populating RepositorySourceLocation property for module Az.Accounts.
##[debug]Loading module from path 'C:\Modules\az_12.1.0\Az.Accounts\3.0.4\Az.Accounts.psm1'.
##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
##[command]Clear-AzContext -Scope Process -ErrorAction Stop
##[debug]Caught exception from task script.
##[debug]Error record:
##[debug]ConvertFrom-Json : Invalid JSON primitive: .
##[debug]At D:\a\_tasks\PublishADFTask_b2032481-f9a9-476d-af8f-9156ee066e1b\2.0.1590\ps_modules\azure.datafactory.tools\private\DeploymentState.class.ps1:65 char:32
##[debug]+         $json = $FileContent | ConvertFrom-Json
##[debug]+                                ~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
##[debug]    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
##[debug] 
##[debug]Script stack trace:
##[debug]at Get-StateFromStorage, D:\a\_tasks\PublishADFTask_b2032481-f9a9-476d-af8f-9156ee066e1b\2.0.1590\ps_modules\azure.datafactory.tools\private\DeploymentState.class.ps1: line 65
##[debug]at Publish-AdfV2FromJson, D:\a\_tasks\PublishADFTask_b2032481-f9a9-476d-af8f-9156ee066e1b\2.0.1590\ps_modules\azure.datafactory.tools\public\Publish-AdfV2FromJson.ps1: line 159
##[debug]at <ScriptBlock>, D:\a\_tasks\PublishADFTask_b2032481-f9a9-476d-af8f-9156ee066e1b\2.0.1590\PublishADF.ps1: line 150
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]System.ArgumentException: Invalid JSON primitive: .
##[debug]   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
##[debug]   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
##[debug]   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
##[debug]   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
##[debug]   at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error)
##[debug]   at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input)
##[debug]   at System.Management.Automation.CommandProcessorBase.Complete()
##[error]Invalid JSON primitive: .
##[debug]Processed: ##vso[task.logissue type=error]Invalid JSON primitive: .
##[debug]Processed: ##vso[task.complete result=Failed]
##[section]Finishing: Publish ADF SQLPlayerDemo-UAT from JSON files.

Version of PowerShell module of:

NowinskiK commented 1 day ago

This happens only in DevOps task (extension) private version, so doesn't affect any users. It because under DevOps, the process saves the state file with UTF8 encoding with BOM, but can't read it correctly.

NowinskiK commented 16 hours ago

https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/understanding-file-encoding?view=powershell-7.4

NowinskiK commented 16 hours ago

https://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom Well... after more tests, this issue apparently can appear in PowerShell tasks as well, but only for ver.5.1.