From f32b67c3bbe0e4a40b20e8da5f09cb674a7da119 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Mon, 15 Mar 2021 14:07:07 +0100 Subject: [PATCH] Simplify error message when config file can't be "stat'd" (#10763) * remove confusing message when a stat error happens while trying to list HCL2 files * leave early if our first GetHCL2Files has errors --- hcl2template/parser.go | 5 +++++ hcl2template/utils.go | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hcl2template/parser.go b/hcl2template/parser.go index 6a14fba13..19e8de0ad 100644 --- a/hcl2template/parser.go +++ b/hcl2template/parser.go @@ -90,6 +90,11 @@ func (p *Parser) Parse(filename string, varFiles []string, argVars map[string]st if filename != "" { hclFiles, jsonFiles, moreDiags := GetHCL2Files(filename, hcl2FileExt, hcl2JsonFileExt) diags = append(diags, moreDiags...) + if moreDiags.HasErrors() { + // here this probably means that the file was not found, let's + // simply leave early. + return nil, diags + } if len(hclFiles)+len(jsonFiles) == 0 { diags = append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, diff --git a/hcl2template/utils.go b/hcl2template/utils.go index 488a5e32a..a8bfffbb8 100644 --- a/hcl2template/utils.go +++ b/hcl2template/utils.go @@ -57,7 +57,6 @@ func GetHCL2Files(filename, hclSuffix, jsonSuffix string) (hclFiles, jsonFiles [ if err != nil { diags = append(diags, &hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: "Cannot tell wether " + filename + " is a directory", Detail: err.Error(), }) return nil, nil, diags