Skip to content

Commit

Permalink
errors.Wrap pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking authored and czimergebot committed Jul 14, 2018
1 parent e414f33 commit f6a92c1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gometalinter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Exclude": [
"exported (\\w+) (\\w+) should have comment or be unexported"
"exported (\\w+) ([\\w\\.]+) should have comment or be unexported"
]
}
30 changes: 18 additions & 12 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func Apply(fs afero.Fs, conf *config.Config, tmp *templates.T, siccMode bool) er

e = applyGlobal(fs, p.Global, &tmp.Global)
if e != nil {
return e
return errors.Wrap(e, "unable to apply global")
}

e = applyModules(fs, p.Modules, &tmp.Module)

return e
return errors.Wrap(e, "unable to apply modules")
}

func applyRepo(fs afero.Fs, p *plan.Plan, repoBox *packr.Box) error {
Expand All @@ -61,7 +61,7 @@ func applyGlobal(fs afero.Fs, p plan.Component, repoBox *packr.Box) error {
path := fmt.Sprintf("%s/global", rootPath)
e := fs.MkdirAll(path, 0755)
if e != nil {
return e
return errors.Wrapf(e, "unable to make directory %s", path)
}
return applyTree(repoBox, afero.NewBasePathFs(fs, path), p.SiccMode, p)
}
Expand All @@ -87,11 +87,11 @@ func applyModules(fs afero.Fs, p map[string]plan.Module, moduleBox *packr.Box) e
path := fmt.Sprintf("%s/modules/%s", rootPath, module)
e = fs.MkdirAll(path, 0755)
if e != nil {
return e
return errors.Wrapf(e, "unable to make path %s", path)
}
e = applyTree(moduleBox, afero.NewBasePathFs(fs, path), modulePlan.SiccMode, modulePlan)
if e != nil {
return e
return errors.Wrap(e, "unable to apply tree")
}
}
return nil
Expand All @@ -102,7 +102,7 @@ func applyEnvs(fs afero.Fs, p *plan.Plan, envBox *packr.Box, componentBox *packr
path := fmt.Sprintf("%s/envs/%s", rootPath, env)
e = fs.MkdirAll(path, 0755)
if e != nil {
return errors.Wrap(e, "unable to make directies for envs")
return errors.Wrapf(e, "unable to make directory %s", path)
}
e := applyTree(envBox, afero.NewBasePathFs(fs, path), envPlan.SiccMode, envPlan)
if e != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func applyTree(source *packr.Box, dest afero.Fs, siccMode bool, subst interface{

e = touchFile(dest, target)
if e != nil {
return e
return errors.Wrapf(e, "unable to touch file %s", target)
}

} else if extension == ".create" {
Expand Down Expand Up @@ -188,11 +188,11 @@ func applyTree(source *packr.Box, dest afero.Fs, siccMode bool, subst interface{
func fmtHcl(fs afero.Fs, path string) error {
in, e := afero.ReadFile(fs, path)
if e != nil {
return e
return errors.Wrapf(e, "unable to read file %s", path)
}
out, e := printer.Format(in)
if e != nil {
return e
return errors.Wrapf(e, "fmt hcl failed for %s", path)
}
return afero.WriteReader(fs, path, bytes.NewReader(out))
}
Expand Down Expand Up @@ -282,11 +282,11 @@ func applyModule(fs afero.Fs, path, mod string, box packr.Box) error {

e = applyTemplate(f, fs, filepath.Join(path, "main.tf"), &moduleData{moduleName, mod, variables, outputs})
if e != nil {
return e
return errors.Wrap(e, "unable to apply template for main.tf")
}
e = fmtHcl(fs, filepath.Join(path, "main.tf"))
if e != nil {
return e
return errors.Wrap(e, "unable to format main.tf")
}

f, e = box.Open("outputs.tf.tmpl")
Expand All @@ -296,9 +296,15 @@ func applyModule(fs afero.Fs, path, mod string, box packr.Box) error {

e = applyTemplate(f, fs, filepath.Join(path, "outputs.tf"), &moduleData{moduleName, mod, variables, outputs})
if e != nil {
return e
return errors.Wrap(e, "unable to apply template for outputs.tf")
}

// TODO
// e = fmtHcl(fs, filepath.Join(path, "outputs.tf"))
// if e != nil {
// return errors.Wrap(e, "unable to format outputs.tf")
// }

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/chanzuckerberg/fogg/config"
"github.com/chanzuckerberg/fogg/util"
"github.com/pkg/errors"
)

type account struct {
Expand Down Expand Up @@ -84,7 +85,7 @@ func Eval(config *config.Config, siccMode, verbose bool) (*Plan, error) {
p := &Plan{}
v, e := util.VersionString()
if e != nil {
return nil, e
return nil, errors.Wrap(e, "unable to parse fogg version")
}
p.Version = v
p.SiccMode = siccMode
Expand Down
1 change: 0 additions & 1 deletion util/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import "fmt"

func Dump(foo interface{}) {
fmt.Printf("%#v\n", foo)

}
2 changes: 1 addition & 1 deletion util/module_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DownloadModule(cacheDir, source string) (string, error) {

e = storage.Get(hash, s, false)
if e != nil {
return "", e
return "", errors.Wrap(e, "unable to read module from local storage")
}
d, _, e := storage.Dir(hash)
if e != nil {
Expand Down

0 comments on commit f6a92c1

Please sign in to comment.