From 86c3c44afec3b6795f25fac46466828b8d4fb441 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 13 Mar 2019 14:59:05 -0700 Subject: [PATCH] switch on err type not string --- packer/core.go | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packer/core.go b/packer/core.go index 630a7dbd5..b9fc2ff9b 100644 --- a/packer/core.go +++ b/packer/core.go @@ -3,7 +3,8 @@ package packer import ( "fmt" "sort" - "strings" + + ttmp "text/template" multierror "github.com/hashicorp/go-multierror" version "github.com/hashicorp/go-version" @@ -346,25 +347,29 @@ func (c *Core) init() error { // Interpolate the default def, err := interpolate.Render(v.Default, ctx) - if err != nil { - if strings.Contains(err.Error(), "error calling user") { - shouldRetry = true - tryCount++ - failedInterpolation = fmt.Sprintf(`"%s": "%s"`, k, v.Default) - continue - } else { - return fmt.Errorf( - // unexpected interpolation error: abort the run - "error interpolating default value for '%s': %s", - k, err) - } - } + switch err.(type) { + case nil: + // We only get here if interpolation has succeeded, so something is + // different in this loop than in the last one. + changed = true + c.variables[k] = def + ctx.UserVariables = c.variables + case ttmp.ExecError: + shouldRetry = true + tryCount++ + failedInterpolation = fmt.Sprintf(`"%s": "%s"`, k, v.Default) + continue - // We only get here if interpolation has succeeded, so something is - // different in this loop than in the last one. - changed = true - c.variables[k] = def - ctx.UserVariables = c.variables + return fmt.Errorf( + // unexpected interpolation error: abort the run + "error interpolating default value for '%s': %s", + k, err) + default: + return fmt.Errorf( + // unexpected interpolation error: abort the run + "error interpolating default value for '%s': %s", + k, err) + } } if tryCount >= 100 { break