Repository navigation
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Milestone
Description
Steps to reproduce
$ConfigPath = New-TemporaryFile
$mypath = Join-Path $env:SystemDrive MyDir
'{ "PSModulePath": "'+$mypath+'" }' | Out-File -Force $ConfigPath
pwsh -NoProfile -NonInteractive -settingsFile $ConfigPath -c "1+1"Expected behavior
Should not crash the process.
Actual behavior
Process terminated. Bad JSON escape sequence: \M. Path 'PSModulePath', line 1, position 23.
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String, System.String[], Int32)
at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
Newtonsoft.Json.JsonReaderException: Bad JSON escape sequence: \M. Path 'PSModulePath', line 1, position 23.
at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.JsonWriter.WriteToken(JsonReader reader, Boolean writeChildren, Boolean writeDateConstructorAsDate, Boolean writeComments)
at Newtonsoft.Json.Linq.JTokenWriter.WriteToken(JsonReader reader, Boolean writeChildren, Boolean writeDateConstructorAsDate, Boolean writeComments)
at Newtonsoft.Json.JsonWriter.WriteToken(JsonReader reader, Boolean writeChildren)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateJToken(JsonReader reader, JsonContract contract)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at System.Management.Automation.Configuration.PowerShellConfig.ReadValueFromFile[T](ConfigScope scope, String key, T defaultValue)
at System.Management.Automation.Configuration.PowerShellConfig.GetPowerShellPolicies(ConfigScope scope)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Management.Automation.Utils.GetPolicySettingFromConfigFile[T](ConfigScope[] preferenceOrder)
at System.Management.Automation.Utils.GetPolicySetting[T](ConfigScope[] preferenceOrder)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.GetModuleLoggingInformation(IEnumerable`1& moduleNames)
at System.Management.Automation.PSSnapInReader.SetSnapInLoggingInformation(PSSnapInInfo psSnapInInfo)
at System.Management.Automation.PSSnapInReader.ReadCoreEngineSnapIn()
at System.Management.Automation.Runspaces.InitialSessionState.ImportCorePSSnapIn()
at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2()
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc)
Environment data
Name Value
---- -----
PSVersion 7.0.0-rc.3
PSEdition Core
GitCommitId 7.0.0-rc.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Activity
vexx32 commentedon Feb 26, 2020
I wonder if that's an issue with the file encoding?
What's the default encoding for Out-File in this context? And what encoding is pwsh expecting on startup?
rjmholt commentedon Feb 26, 2020
Is this because the backslashes in the PSModulePath aren't escaped?
rjmholt commentedon Feb 26, 2020
"C:\MyDir"isn't a valid JSON string; it needs to be"C:\\MyDir"rjmholt commentedon Feb 26, 2020
But we should fix the crash
rjmholt commentedon Feb 26, 2020
(As in, PowerShell shouldn't crash quite as hard)
daxian-dbw commentedon Feb 26, 2020
I remember talking to Travis Plunk (@TravisEz13) about the crash when the setting.json file is bad, and we believe pwsh should terminate in that case for good. But it definitely should be terminated in a more graceful way :)
adityapatwardhan commentedon Aug 20, 2020
We should get a better error message about shutting down as the settings file is corrupted and we cannot determined the security policies in the settings file.