Feature goctl error wrap (#995)
* Add `Wrap` in file errorx.go * Wrap error with `GoctlError` * format code * Refactor package `env` to `version` * Refactor package `IsVersionGatherThan` * fix typo Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
goformat "go/format"
|
||||
"io/ioutil"
|
||||
"text/template"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/internal/errorx"
|
||||
)
|
||||
|
||||
const regularPerm = 0o666
|
||||
@@ -54,12 +56,12 @@ func (t *DefaultTemplate) SaveTo(data interface{}, path string, forceUpdate bool
|
||||
func (t *DefaultTemplate) Execute(data interface{}) (*bytes.Buffer, error) {
|
||||
tem, err := template.New(t.name).Parse(t.text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errorx.Wrap(err, "template parse error:", t.text)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
if err = tem.Execute(buf, data); err != nil {
|
||||
return nil, err
|
||||
return nil, errorx.Wrap(err, "template execute error:", t.text)
|
||||
}
|
||||
|
||||
if !t.goFmt {
|
||||
@@ -68,7 +70,7 @@ func (t *DefaultTemplate) Execute(data interface{}) (*bytes.Buffer, error) {
|
||||
|
||||
formatOutput, err := goformat.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errorx.Wrap(err, "go format error:", string(buf.Bytes()))
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
|
||||
Reference in New Issue
Block a user