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

New-AzResourceGroupDeployment : needs to show Bicep error message on console #14508

Closed
shenglol opened this issue Mar 10, 2021 · 10 comments · Fixed by #14449
Closed

New-AzResourceGroupDeployment : needs to show Bicep error message on console #14508

shenglol opened this issue Mar 10, 2021 · 10 comments · Fixed by #14449
Assignees
Labels
ARM feature-request This issue requires a new behavior in the product in order be resolved.

Comments

@shenglol
Copy link
Contributor

Description

The deployment cmdlet won't work if a Bicep file contains errors. I would expect it to print out the compilation errors. Also, if a Bicep file is valid but has warnings, the warnings will not be printed.

Steps to reproduce

> New-AzResourceGroupDeployment -TemplateFile .\withErrors.bicep -ResourceGroupName test
New-AzResourceGroupDeployment: Cannot retrieve the dynamic parameters for the cmdlet. The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.

Environment data


Module versions

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Debug output

~\Desktop\bicep-bugbash
> $DebugPreference='Continue'

~\Desktop\bicep-bugbash
> New-AzResourceGroupDeployment -TemplateFile .\withErrors.bicep -ResourceGroupName test -Debug
New-AzResourceGroupDeployment: Cannot retrieve the dynamic parameters for the cmdlet. The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.

Error output

DEBUG: 10:25:07 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 10:25:07 AM - using account id 'shenglol@microsoft.com'...
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

   HistoryId: 20

Message        : Cannot retrieve the dynamic parameters for the cmdlet. The WriteObject and WriteError methods cannot
                 be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing
                 methods, and they can only be called from within the same thread. Validate that the cmdlet makes
                 these calls correctly, or contact Microsoft Customer Support Services.
StackTrace     :    at System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(
                 ParameterBindingException& outgoingBindingException)
                    at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidati
                 on(Collection`1 arguments)
                    at
                 System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1
                 arguments)
                    at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
                    at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
                    at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary
                 psDefaultParameterValues)
                    at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
                    at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object
                 input)
                 --- End of stack trace from previous location ---
                    at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object
                 input)
                    at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput,
                 CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
                 commandRedirections, FunctionContext funcContext)
                    at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                 frame)
Exception      : System.Management.Automation.ParameterBindingException
InvocationInfo : {New-AzResourceGroupDeployment}
Line           : New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -ResourceGroupName test
Position       : At line:1 char:1
                 + New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -Resour …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 20

Message        : The WriteObject and WriteError methods cannot be called from outside the overrides of the
                 BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within
                 the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer
                 Support Services.
StackTrace     :    at System.Management.Automation.MshCommandRuntime.ThrowIfWriteNotPermitted(Boolean
                 needsToWriteToPipeline)
                    at System.Management.Automation.MshCommandRuntime.DoWriteError(Object obj)
                    at System.Management.Automation.MshCommandRuntime.WriteError(ErrorRecord errorRecord, Boolean
                 overrideInquire)
                    at System.Management.Automation.MshCommandRuntime.WriteError(ErrorRecord errorRecord)
                    at System.Management.Automation.Cmdlet.WriteError(ErrorRecord errorRecord)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__DisplayClass14_0`1.<Execu
                 teScript>b__0(ErrorRecord e)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.GeneralUtilities.ForEach[T](IEnumerable`1
                 sequence, Action`1 action)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteScript[T](PSCmdlet
                 cmdlet, String contents)
                    at
                 Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities.BicepUtility.BuildFile[T](ScriptExecutor`1
                 executeScript, String bicepTemplateFilePath)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceWithParameterCmdletBase.
                 BuildAndUseBicepTemplate()
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceWithParameterCmdletBase.
                 GetDynamicParameters()
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase.DeploymentCreateCmdle
                 t.GetDynamicParameters()
                    at System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(
                 ParameterBindingException& outgoingBindingException)
Exception      : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {New-AzResourceGroupDeployment}
Line           : New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -ResourceGroupName test
Position       : At line:1 char:1
                 + New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -Resour …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 20

Message        : C:\Users\Shenglong\AppData\Local\Temp\withError.bicep(1,11) : Error BCP004: The string at this
                 location is not terminated due to an unexpected new line character.
StackTrace     :
Exception      : System.Management.Automation.RemoteException
InvocationInfo : {New-AzResourceGroupDeployment}
Line           : New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -ResourceGroupName test
Position       : At line:1 char:1
                 + New-AzResourceGroupDeployment -TemplateFile .\withError.bicep -Resour …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 20
@shenglol shenglol added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Mar 10, 2021
@shenglol
Copy link
Contributor Author

@BethanyZhou FYI.

@dingmeng-xue dingmeng-xue changed the title New-AzResourceGroupDeployment : Cannot retrieve the dynamic parameters for the cmdlet with a Bicep file has errors. New-AzResourceGroupDeployment : needs to show Bicep error message on console Mar 11, 2021
@dingmeng-xue dingmeng-xue added ARM feature-request This issue requires a new behavior in the product in order be resolved. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Mar 11, 2021
@dingmeng-xue dingmeng-xue added this to the S184 (2021-03-23) milestone Mar 11, 2021
@dingmeng-xue
Copy link
Member

According to Azure/bicep#1757, we need to show output of Bicep on PowerShell console.

@BethanyZhou BethanyZhou linked a pull request Mar 11, 2021 that will close this issue
8 tasks
@BethanyZhou
Copy link
Contributor

Thanks @shenglol for your information. This issue has been fixed in #14449. The Bicep error message will be thrown to console in the next release. Besides, all detailed information from Bicep will be available if -Verbose is specified. Thanks.

@davidcorbin-atmosera
Copy link

As of today (in a fresh environment, so everything should be up to date)... still getting the cryptic error of
New-AzDeployment: Cannot retrieve the dynamic parameters for the cmdlet. Cannot find path 'C:\Users\David.Corbin\AppData\Local\Temp\59950199-84c1-4b09-ac62-c8a015a13fc9\Create-Infrastructure.json' because it does not exist.
under various error conditions...

@BethanyZhou
Copy link
Contributor

Thanks for reporting @dcorbin-wintellect . What's your Az.Resources version. Please try to get that by Get-Module

@davidcorbin-atmosera
Copy link

davidcorbin-atmosera commented Feb 17, 2022 via email

@BethanyZhou
Copy link
Contributor

Thanks for your help. @dcorbin-wintellect

  • Do you mind providing your bicep version by running bicep --version in powershell console?
  • Could you reproduce your issue and turn on Verbose and Debug? Like following command New-AzDeployment -TemplateFile test.bicep -ResourceGroup xxx-rg -Verbose -Debug. It will provide more information.

@davidcorbin-atmosera
Copy link

@BethanyZhou -- It was an old install of bicep .... Had not realized that "c:>bicep" and "c:>az bicep" invoked completely different installations...

@BethanyZhou
Copy link
Contributor

Ok, could you run your command with -Verbose -Debug to show us more information?

@davidcorbin-atmosera
Copy link

@BethanyZhou - The machine has since been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants