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

Expose fail function #15958

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Expose fail function #15958

wants to merge 2 commits into from

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Dec 27, 2024

Resolves #14067

This PR exposes the new fail function that is available in the ARM engine. One thing I went back and forth on is what the return type of this function should be. Three viable options are:

  • Error
  • Any
  • Never

My first instinct was to use Error, but this makes the fail function surprisingly difficult to use. It's essentially forbidden everywhere unless you wrap it in any(), which hurts usability. I considered using a return type of any to remove the need for this boilerplate -- this is close to the semantic used in the original C# proposal for throw expressions -- but I wasn't happy with the downstream effects of given Bicep's union type semantics. If fail(...) is of type any, then condition ? 'boo' : fail('boo!') is of type any, since the union of any with anything else is any. This isn't really correct, since the expression will only be evaluated if the condition is true, in which case the ternary's type would be 'boo'.

I ended up choosing never both because a fail(...) expression can't ever finish evaluating (and therefore doesn't really have a type) and because it had the right downstream assignability behavior. Very open to discussion on this if anyone feels strongly that never is incorrect, though!

Microsoft Reviewers: Open in CodeFlow

@jeskew jeskew requested a review from Copilot December 27, 2024 22:12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Bicep.Core/Semantics/Namespaces/SystemNamespaceType.cs:1076

  • [nitpick] The description for the 'fail' function could be clearer. Consider rephrasing to 'Raises a runtime error with the provided message, causing the deployment to fail when evaluated.'
.WithGenericDescription("Raises a runtime error with the provided message. Will cause a deployment to fail when evaluated.")

src/Bicep.Core.IntegrationTests/ScenarioTests.cs:6604

  • [nitpick] The error message 'should have supplied one' is unclear. It should be more descriptive, such as 'A required parameter was not supplied'.
param required string = fail('should have supplied one')
Copy link
Contributor

github-actions bot commented Dec 27, 2024

Test this change out locally with the following install scripts (Action run 12521230248)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 12521230248
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 12521230248"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 12521230248
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 12521230248"

Copy link
Contributor

Dotnet Test Results

    78 files   -     39      78 suites   - 39   30m 37s ⏱️ - 18m 2s
11 566 tests  -     24  11 566 ✅  -     24  0 💤 ±0  0 ❌ ±0 
26 862 runs   - 13 420  26 862 ✅  - 13 420  0 💤 ±0  0 ❌ ±0 

Results for commit 2c339b9. ± Comparison against base commit b732155.

This pull request removes 1846 and adds 632 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K
�0\u0010\u0006�=EO��d2I7ݻ�
A\u000b>h*}`A���Bp�⦶���\u0019�L&�2ݹ~[�CQ7�`\u0006�\u0014s��h=z>@F��\u0005\u0004Xf\u0010"�g�dD״�\u000e�,q�\u000fRY��SY�h��2PV\u001a͆�ل�~���յǼ�\u0017_ݼ<7�\u001f\u001aʩ��\u001f\u001a�z��o��S�\u0001�@m����\u0014��!��d������=A\u0014EQ��'�"�)\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K
�0\u0010\u0006�=E�\u0001ҤyU�{7�\u001b\u000f\u0010�\u0011+���BA���Bܴ��C0�23�I�\u001f\u0012�M�\u0005�Am�b1
	\u001a\u001bu�\u0010��\u001d&4b��"���\u0008�v�Iz�mcj7�\u001c{��(Ʀ�\u000bH���F�(���z�j�P��qe�s��\u0019��boe�^\u000c�/}Lo������o��\ �\u0007p�"A%GTI\u0019��ϒ�?��\u0003\u0007�\u0012�
�\u0006�\u001d\u0014G��
>����ҳy��y�y\u0001:JWL\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��M\u000b�0\u0018\u0007��\u0014�\u0007�{�\u000c<\u0004\u001d2��k�\u001cd��\u001a\u0008}��!�(]Ԃ�;n\u000f������N7+�SSVP`�\u0002\u0008��,�X�z\u000b3	�|A\u0000I�9\u0000^3x'\u001d�U�K��\u0014g� �<]g�����R�����D(5�{��=\u001cz7]���HM\u0003/յh���o_�������S�\u0011a��\u0000J\u0005a�S�\u0004�����L�y�\u001f~�\u001c\u0016�xy\﷉?��\u0004�vO��8���j���\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003��K
�0\u0010\u0006�=EO�ff��{�^!h�\u0007M�\u000f,�w7]\u0008.Z��V0�2�0\u0013���;�o\u000bw(�c�6�ln"�R��\u000f@\u0001\u0003�"�0Jiƒ~�MFtM���\u0012�~\u0010�ĵ�����"26˸%\u000b\u0006q\u0013j��\u001a$W�\u001e��_|u���T~h(�\u001a��h4��~ߚ�)�B \u0003i�4�V\u0014�\u000f\u0012C�\u0017�����X{�(��h
O\u0013@�S\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003��K
�0\u0010\u0006�=E�\u0001bҼZ�{7�\u001b\u000f\u0010�\u0011+���B@���Bܴ��C0�230\u0013�\u001f��\u001b�\u0005�Aݐ0\u000e�5Ac��\u0012���ÄFL�QD�T\u001c!lGߤǽiM�V�c�\u000f
#lڼ��i.9�1eDR&e\u0014�\-\u001d��\u0018W�='y��%��Vv��P����\u0006|�o�\u0019��O�@�\u000f�\�\I������ϒ�?��\u0003\u0007�\u0012l\u0005i\u000b�\u000e�#��\u0006�̵��һy��y�y\u0001䣺�\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���\u000b�0\u0014\u0007��+�?`��\�!�\u0011\u0016\u0004]c� \u0003-�@�o\u001e���E-h����1�\u000f\u0006;ݬ�NMYA�H\u0018@04d	�:�[�I��\u000b\u0002HrA\u0001��'�p�j]�Q����H��:�M�%�J�\u0010d!�T���;��a��t}��"5
�Tע-��ʿ�L�������)��0`w\u0000��P�\u0019@�si�?I&�<�\u000f?N\u000e�M�<���ğ{v\u0003�{&�q\u001cg|O\u0007��P\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: custom errors
1 participant