Fixed Bicep expand hangs analysis #858 (#859)

This commit is contained in:
Bernie White 2021-08-10 14:38:54 +10:00 коммит произвёл GitHub
Родитель e80faab5e2
Коммит 86cc7927ab
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 26 добавлений и 4 удалений

Просмотреть файл

@ -7,6 +7,11 @@ See [troubleshooting guide] for a workaround to this issue.
## Unreleased
What's changed since pre-release v1.6.0-B2108023:
- Bug fixes:
- Fixed Bicep expand hangs analysis. [#858](https://github.com/Azure/PSRule.Rules.Azure/issues/858)
## v1.6.0-B2108023 (pre-release)
What's changed since pre-release v1.6.0-B2107028:

Просмотреть файл

@ -33,6 +33,7 @@ In addition, currently the following limitation apply to using Bicep source file
To modules with mandatory parameters you can [exclude files by path spec][2].
Expand from a `main.bicep` that is intended to be deployed directly to Azure.
- Location of issues in Bicep source files is not supported.
- Expansion of Bicep source files times out after 3 seconds.
[1]: using-templates.md#featuresupport
[2]: setup/configuring-expansion.md#excludingfiles

Просмотреть файл

@ -82,11 +82,15 @@ namespace PSRule.Rules.Azure.Data.Bicep
try
{
if (!bicep.HasExited)
bicep.WaitForExit();
if (bicep.ExitCode != 0)
{
var error = bicep.StandardError.ReadToEnd();
var timeoutCount = 0;
while (!bicep.WaitForExit(1000) && !bicep.HasExited && timeoutCount < 3)
timeoutCount++;
}
if (!bicep.HasExited || bicep.ExitCode != 0)
{
var error = bicep.HasExited ? bicep.StandardError.ReadToEnd() : PSRuleResources.BicepCompileTimeout;
throw new BicepCompileException(string.Format(Thread.CurrentThread.CurrentCulture, PSRuleResources.BicepCompileError, path, error), null, path);
}

Просмотреть файл

@ -123,6 +123,15 @@ namespace PSRule.Rules.Azure.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Bicep compilation hasn&apos;t completed within the timeout window. This can be caused by errors or warnings. Check the Bicep output by running bicep build and addressing any issues..
/// </summary>
internal static string BicepCompileTimeout {
get {
return ResourceManager.GetString("BicepCompileTimeout", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to expand resources because the source file &apos;{0}&apos; was not valid. {1}.
/// </summary>

Просмотреть файл

@ -138,6 +138,9 @@
<data name="BicepCompileError" xml:space="preserve">
<value>Bicep compilation of '{0}' failed with: {1}</value>
</data>
<data name="BicepCompileTimeout" xml:space="preserve">
<value>Bicep compilation hasn't completed within the timeout window. This can be caused by errors or warnings. Check the Bicep output by running bicep build and addressing any issues.</value>
</data>
<data name="BicepExpandInvalid" xml:space="preserve">
<value>Unable to expand resources because the source file '{0}' was not valid. {1}</value>
</data>