in src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs [49:247]
private Diagnostic CoreError(string code, string message) => CoreDiagnostic(
DiagnosticLevel.Error,
code,
message);
private Diagnostic CoreWarning(string code, string message) => CoreDiagnostic(
DiagnosticLevel.Warning,
code,
message);
private static string ToQuotedString(IEnumerable<string> elements)
=> elements.Any() ? $"\"{elements.ConcatString("\", \"")}\"" : "";
private static string ToQuotedStringWithCaseInsensitiveOrdering(IEnumerable<string> elements)
=> ToQuotedString(elements.OrderBy(s => s, StringComparer.OrdinalIgnoreCase));
private static string BuildVariableDependencyChainClause(IEnumerable<string>? variableDependencyChain) => variableDependencyChain is not null
? $" You are referencing a variable which cannot be calculated at the start (\"{string.Join("\" -> \"", variableDependencyChain)}\")."
: string.Empty;
private static string BuildNonDeployTimeConstantPropertyClause(string? accessedSymbolName, string? propertyName) =>
accessedSymbolName is not null && propertyName is not null
? $" The property \"{propertyName}\" of {accessedSymbolName} cannot be calculated at the start."
: string.Empty;
private static string BuildAccessiblePropertiesClause(string? accessedSymbolName, IEnumerable<string>? accessiblePropertyNames) => accessedSymbolName is not null && accessiblePropertyNames is not null
? $" Properties of {accessedSymbolName} which can be calculated at the start include {ToQuotedString(accessiblePropertyNames.OrderBy(s => s))}."
: string.Empty;
private static string BuildInvalidOciArtifactReferenceClause(string? aliasName, string referenceValue) => aliasName is not null
? $"The OCI artifact reference \"{referenceValue}\" after resolving alias \"{aliasName}\" is not valid."
: $"The specified OCI artifact reference \"{referenceValue}\" is not valid.";
private static string BuildInvalidTemplateSpecReferenceClause(string? aliasName, string referenceValue) => aliasName is not null
? $"The Template Spec reference \"{referenceValue}\" after resolving alias \"{aliasName}\" is not valid."
: $"The specified Template Spec reference \"{referenceValue}\" is not valid.";
private static string BuildBicepConfigurationClause(IOUri? configFileUri) => configFileUri is not null
? $"Bicep configuration \"{configFileUri}\""
: $"built-in Bicep configuration";
public Diagnostic UnrecognizedToken(string token) => CoreError(
"BCP001",
$"The following token is not recognized: \"{token}\".");
public Diagnostic UnterminatedMultilineComment() => CoreError(
"BCP002",
"The multi-line comment at this location is not terminated. Terminate it with the */ character sequence.");
public Diagnostic UnterminatedString() => CoreError(
"BCP003",
"The string at this location is not terminated. Terminate the string with a single quote character.");
public Diagnostic UnterminatedStringWithNewLine() => CoreError(
"BCP004",
"The string at this location is not terminated due to an unexpected new line character.");
public Diagnostic UnterminatedStringEscapeSequenceAtEof() => CoreError(
"BCP005",
"The string at this location is not terminated. Complete the escape sequence and terminate the string with a single unescaped quote character.");
public Diagnostic UnterminatedStringEscapeSequenceUnrecognized(IEnumerable<string> escapeSequences) => CoreError(
"BCP006",
$"The specified escape sequence is not recognized. Only the following escape sequences are allowed: {ToQuotedString(escapeSequences)}.");
public Diagnostic UnrecognizedDeclaration() => CoreError(
"BCP007",
"This declaration type is not recognized. Specify a metadata, parameter, variable, resource, or output declaration.");
public Diagnostic ExpectedParameterContinuation() => CoreError(
"BCP008",
"Expected the \"=\" token, or a newline at this location.");
public Diagnostic UnrecognizedExpression() => CoreError(
"BCP009",
"Expected a literal value, an array, an object, a parenthesized expression, or a function call at this location.");
public Diagnostic InvalidInteger() => CoreError(
"BCP010",
"Expected a valid 64-bit signed integer.");
public Diagnostic InvalidType() => CoreError(
"BCP011",
"The type of the specified value is incorrect. Specify a string, boolean, or integer literal.");
public Diagnostic ExpectedKeyword(string keyword) => CoreError(
"BCP012",
$"Expected the \"{keyword}\" keyword at this location.");
public Diagnostic ExpectedParameterIdentifier() => CoreError(
"BCP013",
"Expected a parameter identifier at this location.");
public Diagnostic ExpectedVariableIdentifier() => CoreError(
"BCP015",
"Expected a variable identifier at this location.");
public Diagnostic ExpectedOutputIdentifier() => CoreError(
"BCP016",
"Expected an output identifier at this location.");
public Diagnostic ExpectedResourceIdentifier() => CoreError(
"BCP017",
"Expected a resource identifier at this location.");
public Diagnostic ExpectedCharacter(string character) => CoreError(
"BCP018",
$"Expected the \"{character}\" character at this location.");
public Diagnostic ExpectedNewLine() => CoreError(
"BCP019",
"Expected a new line character at this location.");
public Diagnostic ExpectedFunctionOrPropertyName() => CoreError(
"BCP020",
"Expected a function or property name at this location.");
public Diagnostic ExpectedNumericLiteral() => CoreError(
"BCP021",
"Expected a numeric literal at this location.");
public Diagnostic ExpectedPropertyName() => CoreError(
"BCP022",
"Expected a property name at this location.");
public Diagnostic ExpectedVariableOrFunctionName() => CoreError(
"BCP023",
"Expected a variable or function name at this location.");
public Diagnostic IdentifierNameExceedsLimit() => CoreError(
"BCP024",
$"The identifier exceeds the limit of {LanguageConstants.MaxIdentifierLength}. Reduce the length of the identifier.");
public Diagnostic PropertyMultipleDeclarations(string property) => CoreError(
"BCP025",
$"The property \"{property}\" is declared multiple times in this object. Remove or rename the duplicate properties.");
public Diagnostic OutputTypeMismatch(TypeSymbol expectedType, TypeSymbol actualType) => CoreError(
"BCP026",
$"The output expects a value of type \"{expectedType}\" but the provided value is of type \"{actualType}\".");
public Diagnostic IdentifierMultipleDeclarations(string identifier) => CoreError(
"BCP028",
$"Identifier \"{identifier}\" is declared multiple times. Remove or rename the duplicates.");
public Diagnostic InvalidResourceType() => CoreError(
"BCP029",
"The resource type is not valid. Specify a valid resource type of format \"<type-name>@<apiVersion>\".");
public Diagnostic InvalidOutputType(IEnumerable<string> validTypes) => CoreError(
"BCP030",
$"The output type is not valid. Please specify one of the following types: {ToQuotedString(validTypes)}.");
public Diagnostic InvalidParameterType(IEnumerable<string> validTypes) => CoreError(
"BCP031",
$"The parameter type is not valid. Please specify one of the following types: {ToQuotedString(validTypes)}.");
public Diagnostic CompileTimeConstantRequired() => CoreError(
"BCP032",
"The value must be a compile-time constant.");
public Diagnostic ExpectedValueTypeMismatch(bool warnInsteadOfError, TypeSymbol expectedType, TypeSymbol actualType) => CoreDiagnostic(
warnInsteadOfError ? DiagnosticLevel.Warning : DiagnosticLevel.Error,
"BCP033",
$"Expected a value of type \"{expectedType}\" but the provided value is of type \"{actualType}\".");
public Diagnostic ArrayTypeMismatch(bool warnInsteadOfError, TypeSymbol expectedType, TypeSymbol actualType) => CoreDiagnostic(
warnInsteadOfError ? DiagnosticLevel.Warning : DiagnosticLevel.Error,
"BCP034",
$"The enclosing array expected an item of type \"{expectedType}\", but the provided item was of type \"{actualType}\".");
public Diagnostic MissingRequiredProperties(bool warnInsteadOfError, Symbol? sourceDeclaration, ObjectSyntax? objectSyntax, ICollection<string> properties, string blockName, bool showTypeInaccuracy, IDiagnosticLookup parsingErrorLookup)
{
var sourceDeclarationClause = sourceDeclaration is not null
? $" from source declaration \"{sourceDeclaration.Name}\""
: string.Empty;
if (objectSyntax is null ||
SyntaxModifier.TryAddProperties(
objectSyntax,
properties.Select(p => SyntaxFactory.CreateObjectProperty(p, SyntaxFactory.EmptySkippedTrivia)),
parsingErrorLookup) is not { } newSyntax)
{
// We're unable to come up with an automatic code fix - most likely because there are unhandled parse errors
return CoreDiagnostic(
warnInsteadOfError ? DiagnosticLevel.Warning : DiagnosticLevel.Error,
"BCP035",
$"The specified \"{blockName}\" declaration is missing the following required properties{sourceDeclarationClause}: {ToQuotedString(properties)}.{(showTypeInaccuracy ? TypeInaccuracyClause : string.Empty)}");
}
var codeFix = new CodeFix("Add required properties", true, CodeFixKind.QuickFix, new CodeReplacement(objectSyntax.Span, newSyntax.ToString()));
return CoreDiagnostic(
warnInsteadOfError ? DiagnosticLevel.Warning : DiagnosticLevel.Error,
"BCP035",
$"The specified \"{blockName}\" declaration is missing the following required properties{sourceDeclarationClause}: {ToQuotedString(properties)}.{(showTypeInaccuracy ? TypeInaccuracyClause : string.Empty)}")
with
{ Fixes = [codeFix] };
}