text/template turns out to swallow custom error types.
This commit is contained in:
parent
2bbc3d50d7
commit
e54b1cedd9
|
@ -3,6 +3,7 @@ package packer
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
ttmp "text/template"
|
||||
|
||||
|
@ -367,12 +368,10 @@ func (c *Core) init() error {
|
|||
ctx.UserVariables = c.variables
|
||||
case ttmp.ExecError:
|
||||
castError := err.(ttmp.ExecError)
|
||||
switch castError.Err.(type) {
|
||||
case interpolate.ErrVariableNotSet:
|
||||
if strings.Contains(castError.Error(), interpolate.ErrVariableNotSetString) {
|
||||
shouldRetry = true
|
||||
failedInterpolation = fmt.Sprintf(`"%s": "%s"; error: %s`, k, v, err)
|
||||
continue
|
||||
default:
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -47,13 +47,7 @@ var FuncGens = map[string]FuncGenerator{
|
|||
"lower": funcGenPrimitive(strings.ToLower),
|
||||
}
|
||||
|
||||
type ErrVariableNotSet struct {
|
||||
Var string // Name of template.
|
||||
}
|
||||
|
||||
func (e ErrVariableNotSet) Error() string {
|
||||
return fmt.Sprintf("variable %s not set", e.Var)
|
||||
}
|
||||
var ErrVariableNotSetString = "Error: variable not set:"
|
||||
|
||||
// FuncGenerator is a function that given a context generates a template
|
||||
// function for the template.
|
||||
|
@ -176,7 +170,7 @@ func funcGenUser(ctx *Context) interface{} {
|
|||
// error and retry if we're interpolating UserVariables. But if
|
||||
// we're elsewhere in the template, just return the empty string.
|
||||
if !ok {
|
||||
return "", ErrVariableNotSet{k}
|
||||
return "", fmt.Errorf("%s %s", ErrVariableNotSetString, k)
|
||||
}
|
||||
}
|
||||
return val, nil
|
||||
|
|
Loading…
Reference in New Issue