regroup duplicate error message

This commit is contained in:
Adrien Delorme 2020-01-06 17:10:12 +01:00
parent 0102f5b6fa
commit 79d7b3e636
1 changed files with 4 additions and 13 deletions

View File

@ -48,23 +48,14 @@ func (p *Parser) decodeBuildConfig(block *hcl.Block) (*BuildBlock, hcl.Diagnosti
for _, buildFrom := range b.FromSources {
ref := sourceRefFromString(buildFrom)
if ref == NoSource {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid " + sourceLabel + " reference: " + buildFrom,
Detail: "A " + sourceLabel + " type must start with a letter and " +
"may contain only letters, digits, underscores, and dashes." +
"A valid source reference looks like: `source.type.name`",
Subject: block.DefRange.Ptr(),
})
continue
}
if !hclsyntax.ValidIdentifier(ref.Type) ||
if ref == NoSource ||
!hclsyntax.ValidIdentifier(ref.Type) ||
!hclsyntax.ValidIdentifier(ref.Name) {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid " + sourceLabel + " reference",
Detail: "A " + sourceLabel + " type must start with a letter and " +
Detail: "A " + sourceLabel + " type is made of three parts that are" +
"split by a dot `.`; each part must start with a letter and " +
"may contain only letters, digits, underscores, and dashes." +
"A valid source reference looks like: `source.type.name`",
Subject: block.DefRange.Ptr(),