func WrappedErrorf(template string, args ...interface{}) dst.Expr {
	return CallQualifiedFunc(
		"errors",
		"Wrap",
		dst.NewIdent("err"),
		StringLiteralf(template, args...))
}
WrappedErrorf returns the err local, wrapped with additional information

errors.Wrap(err, <message>)
package astbuilder
import (
	"fmt"
	"go/token"
	"github.com/dave/dst"
)
func CheckErrorAndReturn(otherReturns ...dst.Expr) dst.Stmt {
	returnValues := append([]dst.Expr{}, cloneExprSlice(otherReturns)...)
	returnValues = append(returnValues, dst.NewIdent("err"))
	return &dst.IfStmt{
		Cond: &dst.BinaryExpr{
			X:  dst.NewIdent("err"),
			Op: token.NEQ,
			Y:  dst.NewIdent("nil"),
		},
		Body: &dst.BlockStmt{
			List: []dst.Stmt{
				&dst.ReturnStmt{
					Results: returnValues,
				},
			},
		},
	}
}
func NewVariableQualified(varName string, qualifier string, structName string) dst.Stmt {
	return &dst.DeclStmt{
		Decl: &dst.GenDecl{
			Tok: token.VAR,
			Specs: []dst.Spec{
				&dst.TypeSpec{
					Name: dst.NewIdent(varName),
					Type: &dst.SelectorExpr{
						X:   dst.NewIdent(qualifier),
						Sel: dst.NewIdent(structName),
					},
				},
			},
		},
	}
}
func NewVariable(varName string, structName string) dst.Stmt {
	return &dst.DeclStmt{
		Decl: &dst.GenDecl{
			Tok: token.VAR,
			Specs: []dst.Spec{
				&dst.TypeSpec{
					Name: dst.NewIdent(varName),
					Type: dst.NewIdent(structName),
				},
			},
		},
	}
}
func LocalVariableDeclaration(ident string, typ dst.Expr, comment string) dst.Stmt {
	return &dst.DeclStmt{
		Decl: VariableDeclaration(ident, typ, comment),
	}
}
func VariableDeclaration(ident string, typ dst.Expr, comment string) *dst.GenDecl {
	decl := &dst.GenDecl{
		Tok: token.VAR,
		Specs: []dst.Spec{
			&dst.ValueSpec{
				Names: []*dst.Ident{
					dst.NewIdent(ident),
				},
				Type: dst.Clone(typ).(dst.Expr),
			},
		},
	}
	AddWrappedComment(&decl.Decs.Start, comment, 80)
	return decl
}
func TypeAssert(lhs dst.Expr, rhs dst.Expr, typ dst.Expr) *dst.AssignStmt {
	return &dst.AssignStmt{
		Lhs: []dst.Expr{
			dst.Clone(lhs).(dst.Expr),
			dst.NewIdent("ok"),
		},
		Tok: token.DEFINE,
		Rhs: []dst.Expr{
			&dst.TypeAssertExpr{
				X:    dst.Clone(rhs).(dst.Expr),
				Type: dst.Clone(typ).(dst.Expr),
			},
		},
	}
}
func ReturnIfOk(returns ...dst.Expr) *dst.IfStmt {
	return ReturnIfExpr(dst.NewIdent("ok"), returns...)
}
func ReturnIfNotOk(returns ...dst.Expr) *dst.IfStmt {
	return ReturnIfExpr(
		&dst.UnaryExpr{
			Op: token.NOT,
			X:  dst.NewIdent("ok"),
		},
		returns...)
}
func ReturnIfNil(toCheck dst.Expr, returns ...dst.Expr) dst.Stmt {
	return ReturnIfExpr(
		&dst.BinaryExpr{
			X:  dst.Clone(toCheck).(dst.Expr),
			Op: token.EQL,
			Y:  dst.NewIdent("nil"),
		},
		returns...)
}
func ReturnIfNotNil(toCheck dst.Expr, returns ...dst.Expr) dst.Stmt {
	return ReturnIfExpr(
		&dst.BinaryExpr{
			X:  dst.Clone(toCheck).(dst.Expr),
			Op: token.NEQ,
			Y:  dst.NewIdent("nil"),
		},
		returns...)
}
func ReturnIfExpr(cond dst.Expr, returns ...dst.Expr) *dst.IfStmt {
	if len(returns) == 0 {
		panic("Expected at least 1 return for ReturnIfOk")
	}
	return &dst.IfStmt{
		Cond: cond,
		Body: &dst.BlockStmt{
			List: []dst.Stmt{
				&dst.ReturnStmt{
					Results: cloneExprSlice(returns),
				},
			},
		},
	}
}
func FormatError(fmtPackage string, formatString string, args ...dst.Expr) dst.Expr {
	var callArgs []dst.Expr
	callArgs = append(
		callArgs,
		StringLiteral(formatString))
	callArgs = append(callArgs, args...)
	return CallQualifiedFunc(fmtPackage, "Errorf", callArgs...)
}
func AddrOf(expr dst.Expr) *dst.UnaryExpr {
	return &dst.UnaryExpr{
		Op: token.AND,
		X:  dst.Clone(expr).(dst.Expr),
	}
}
func Dereference(expr dst.Expr) *dst.UnaryExpr {
	return &dst.UnaryExpr{
		Op: token.MUL,
		X:  dst.Clone(expr).(dst.Expr),
	}
}
func Returns(returns ...dst.Expr) dst.Stmt {
	return &dst.ReturnStmt{
		Decs: dst.ReturnStmtDecorations{
			NodeDecs: dst.NodeDecs{
				Before: dst.NewLine,
			},
		},
		Results: cloneExprSlice(returns),
	}
}
func ReturnNoError() dst.Stmt {
	result := Returns(dst.NewIdent("nil"))
	result.Decorations().Before = dst.EmptyLine
	result.Decorations().Start.Append("// No error")
	return result
}