about summary refs log tree commit diff
path: root/templater
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-03-09T14·17+0100
committerVincent Ambo <github@tazj.in>2018-03-09T14·23+0100
commit3aa2cb8d3efe04eda8cf1d0d2dcb5ad8ddf21147 (patch)
tree45187c7d315d744a820706579222f66626bb0a80 /templater
parentb8722ce83bce727d88a61cecff3343d3046e75f7 (diff)
refactor: Remove old error handling library
Removes the old error handling library and switches to plain
fmt.Errorf calls.

There are several reasons for this:

* There are no useful types or handling here anyways, so output format
  is the only priority.
* Users don't care about getting stacktraces.
* My emotional wellbeing.

Fin de siècle.
Diffstat (limited to 'templater')
-rw-r--r--templater/dns.go12
-rw-r--r--templater/pass.go13
-rw-r--r--templater/templater.go29
3 files changed, 5 insertions, 49 deletions
diff --git a/templater/dns.go b/templater/dns.go
index 096ceb1dfd52..e6b21068041a 100644
--- a/templater/dns.go
+++ b/templater/dns.go
@@ -14,26 +14,16 @@ package templater
 
 import (
 	"fmt"
-	"github.com/polydawn/meep"
 	"net"
 	"os"
 )
 
-type DNSError struct {
-	meep.TraitAutodescribing
-	meep.TraitCausable
-	Output string
-}
-
 func GetIPsFromDNS(host string) ([]interface{}, error) {
 	fmt.Fprintf(os.Stderr, "Attempting to look up IP for %s in DNS\n", host)
 	ips, err := net.LookupIP(host)
 
 	if err != nil {
-		return nil, meep.New(
-			&DNSError{Output: "IP address lookup failed"},
-			meep.Cause(err),
-		)
+		return nil, fmt.Errorf("IP address lookup failed: %v", err)
 	}
 
 	var result []interface{} = make([]interface{}, len(ips))
diff --git a/templater/pass.go b/templater/pass.go
index ecddff7402ca..53d8f2f9bc6b 100644
--- a/templater/pass.go
+++ b/templater/pass.go
@@ -16,27 +16,16 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
-
-	"github.com/polydawn/meep"
 	"strings"
 )
 
-type PassError struct {
-	meep.TraitAutodescribing
-	meep.TraitCausable
-	Output string
-}
-
 func GetFromPass(key string) (string, error) {
 	fmt.Fprintf(os.Stderr, "Attempting to look up %s in pass\n", key)
 	pass := exec.Command("pass", "show", key)
 
 	output, err := pass.CombinedOutput()
 	if err != nil {
-		return "", meep.New(
-			&PassError{Output: string(output)},
-			meep.Cause(err),
-		)
+		return "", fmt.Errorf("Pass lookup failed: %s (%v)", output, err)
 	}
 
 	trimmed := strings.TrimSpace(string(output))
diff --git a/templater/templater.go b/templater/templater.go
index fd514a5ac06f..bfd2af1f61bf 100644
--- a/templater/templater.go
+++ b/templater/templater.go
@@ -20,26 +20,12 @@ import (
 	"text/template"
 
 	"github.com/Masterminds/sprig"
-	"github.com/polydawn/meep"
 	"github.com/tazjin/kontemplate/context"
 	"github.com/tazjin/kontemplate/util"
 )
 
 const failOnMissingKeys string = "missingkey=error"
 
-// Error that is caused by non-existent template files being specified
-type TemplateNotFoundError struct {
-	meep.AllTraits
-	Name string
-	Path string
-}
-
-// Error that is caused during templating, e.g. required value being absent or invalid template format
-type TemplatingError struct {
-	meep.TraitAutodescribing
-	meep.TraitCausable
-}
-
 type RenderedResource struct {
 	Filename string
 	Rendered string
@@ -83,10 +69,7 @@ func processResourceSet(c *context.Context, rs *context.ResourceSet) (*RenderedR
 	resources, err := processFiles(c, rs, rp, files)
 
 	if err != nil {
-		return nil, meep.New(
-			&TemplateNotFoundError{Name: rs.Name, Path: rs.Path},
-			meep.Cause(err),
-		)
+		return nil, err
 	}
 
 	return &RenderedResourceSet{
@@ -122,10 +105,7 @@ func templateFile(c *context.Context, rs *context.ResourceSet, filename string)
 	tpl, err := template.New(path.Base(filename)).Funcs(templateFuncs(rs)).Option(failOnMissingKeys).ParseFiles(filename)
 
 	if err != nil {
-		return "", meep.New(
-			&TemplateNotFoundError{Name: filename},
-			meep.Cause(err),
-		)
+		return "", fmt.Errorf("Template %s not found: %v", filename, err)
 	}
 
 	var b bytes.Buffer
@@ -135,10 +115,7 @@ func templateFile(c *context.Context, rs *context.ResourceSet, filename string)
 	err = tpl.Execute(&b, rs.Values)
 
 	if err != nil {
-		return "", meep.New(
-			&TemplatingError{},
-			meep.Cause(err),
-		)
+		return "", fmt.Errorf("Error while templating %s: %v", filename, err)
 	}
 
 	return b.String(), nil