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

Reword scope errors to clarify behavior #5860

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Bicep.Core.IntegrationTests/NestedResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public void Nested_resource_blocks_existing_parents_at_different_scopes(string p
");

result.Diagnostics.ExcludingLinterDiagnostics().ExcludingMissingTypes().Should().HaveDiagnostics(new[] {
("BCP165", DiagnosticLevel.Error, "Cannot deploy a resource with ancestor under a different scope. Resource \"res1\" has the \"scope\" property set."),
("BCP165", DiagnosticLevel.Error, "A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the \"scope\" property value assigned to ancestor resource \"res1\". You must use modules to deploy resources to a different scope."),
});
}

Expand Down Expand Up @@ -830,7 +830,7 @@ public void Nested_resource_blocks_scope_on_child_resources()
{
template.Should().NotHaveValue();
diags.ExcludingLinterDiagnostics().ExcludingMissingTypes().Should().HaveDiagnostics(new[] {
("BCP164", DiagnosticLevel.Error, "The \"scope\" property is unsupported for a resource with a parent resource. This resource has \"res2\" declared as its parent."),
("BCP164", DiagnosticLevel.Error, "A child resource's scope is computed based on the scope of its ancestor resource. This means that using the \"scope\" property on a child resource is unsupported."),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void Parent_property_blocks_existing_parents_at_different_scopes(string p
");

result.Diagnostics.ExcludingLinterDiagnostics().ExcludingMissingTypes().Should().HaveDiagnostics(new[] {
("BCP165", DiagnosticLevel.Error, "Cannot deploy a resource with ancestor under a different scope. Resource \"res1\" has the \"scope\" property set."),
("BCP165", DiagnosticLevel.Error, "A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the \"scope\" property value assigned to ancestor resource \"res1\". You must use modules to deploy resources to a different scope."),
});
}

Expand Down Expand Up @@ -257,7 +257,7 @@ public void Parent_property_blocks_scope_on_child_resources()
{
template.Should().NotHaveValue();
diags.ExcludingLinterDiagnostics().ExcludingMissingTypes().Should().HaveDiagnostics(new[] {
("BCP164", DiagnosticLevel.Error, "The \"scope\" property is unsupported for a resource with a parent resource. This resource has \"res2\" declared as its parent."),
("BCP164", DiagnosticLevel.Error, "A child resource's scope is computed based on the scope of its ancestor resource. This means that using the \"scope\" property on a child resource is unsupported."),
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ param groupReaderId string

result.Template.Should().NotHaveValue();
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP139", DiagnosticLevel.Error, "The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module."),
("BCP139", DiagnosticLevel.Error, "The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module."),
("BCP139", DiagnosticLevel.Error, "The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module."),
("BCP139", DiagnosticLevel.Error, "A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope."),
("BCP139", DiagnosticLevel.Error, "A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope."),
("BCP139", DiagnosticLevel.Error, "A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope."),
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/ScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void Errors_are_raised_for_extensions_of_existing_resources_at_invalid_sc
"));

diags.Should().HaveDiagnostics(new[] {
("BCP139", DiagnosticLevel.Error, "The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module."),
("BCP139", DiagnosticLevel.Error, "A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope."),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ resource invalidScope3 'My.Rp/mockResource@2020-12-01' = {
//@[23:54) [BCP081 (Warning)] Resource type "My.Rp/mockResource@2020-12-01" does not have types available. (CodeDescription: none) |'My.Rp/mockResource@2020-12-01'|
name: 'invalidScope3'
scope: subscription()
//@[9:23) [BCP139 (Error)] The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module. (CodeDescription: none) |subscription()|
//@[9:23) [BCP139 (Error)] A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope. (CodeDescription: none) |subscription()|
}

resource invalidDuplicateName1 'Mock.Rp/mockResource@2020-01-01' = {
Expand Down Expand Up @@ -1854,7 +1854,7 @@ resource p1_res1 'Microsoft.Rp1/resource1@2020-06-01' existing = {

resource p1_child1 'Microsoft.Rp1/resource1/child1@2020-06-01' = {
//@[19:62) [BCP081 (Warning)] Resource type "Microsoft.Rp1/resource1/child1@2020-06-01" does not have types available. (CodeDescription: none) |'Microsoft.Rp1/resource1/child1@2020-06-01'|
//@[65:106) [BCP165 (Error)] Cannot deploy a resource with ancestor under a different scope. Resource "p1_res1" has the "scope" property set. (CodeDescription: none) |{\r\n parent: p1_res1\r\n name: 'child1'\r\n}|
//@[65:106) [BCP165 (Error)] A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the "scope" property value assigned to ancestor resource "p1_res1". You must use modules to deploy resources to a different scope. (CodeDescription: none) |{\r\n parent: p1_res1\r\n name: 'child1'\r\n}|
parent: p1_res1
name: 'child1'
}
Expand All @@ -1874,7 +1874,7 @@ resource p2_res2 'Microsoft.Rp2/resource2@2020-06-01' = {
resource p2_res2child 'Microsoft.Rp2/resource2/child2@2020-06-01' = {
//@[22:65) [BCP081 (Warning)] Resource type "Microsoft.Rp2/resource2/child2@2020-06-01" does not have types available. (CodeDescription: none) |'Microsoft.Rp2/resource2/child2@2020-06-01'|
scope: p2_res1
//@[9:16) [BCP164 (Error)] The "scope" property is unsupported for a resource with a parent resource. This resource has "p2_res2" declared as its parent. (CodeDescription: none) |p2_res1|
//@[9:16) [BCP164 (Error)] A child resource's scope is computed based on the scope of its ancestor resource. This means that using the "scope" property on a child resource is unsupported. (CodeDescription: none) |p2_res1|
parent: p2_res2
name: 'child2'
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ public Diagnostic RuntimeValueNotAllowedInProperty(string propertyName, string?
TextSpan,
DiagnosticLevel.Error,
"BCP139",
$"The root resource scope must match that of the Bicep file. To deploy a resource to a different root scope, use a module.");
$"A resource's scope must match the scope of the Bicep file for it to be deployable. You must use modules to deploy resources to a different scope.");

public ErrorDiagnostic UnterminatedMultilineString() => new(
TextSpan,
Expand Down Expand Up @@ -988,12 +988,12 @@ public Diagnostic RuntimeValueNotAllowedInProperty(string propertyName, string?
public ErrorDiagnostic ScopeUnsupportedOnChildResource(string parentIdentifier) => new(
TextSpan,
"BCP164",
$"The \"{LanguageConstants.ResourceScopePropertyName}\" property is unsupported for a resource with a parent resource. This resource has \"{parentIdentifier}\" declared as its parent.");
$"A child resource's scope is computed based on the scope of its ancestor resource. This means that using the \"{LanguageConstants.ResourceScopePropertyName}\" property on a child resource is unsupported.");

public ErrorDiagnostic ScopeDisallowedForAncestorResource(string ancestorIdentifier) => new(
TextSpan,
"BCP165",
$"Cannot deploy a resource with ancestor under a different scope. Resource \"{ancestorIdentifier}\" has the \"{LanguageConstants.ResourceScopePropertyName}\" property set.");
$"A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the \"{LanguageConstants.ResourceScopePropertyName}\" property value assigned to ancestor resource \"{ancestorIdentifier}\". You must use modules to deploy resources to a different scope.");

public ErrorDiagnostic DuplicateDecorator(string decoratorName) => new(
TextSpan,
Expand Down