修复: byte/rune 长度混淆及错误位置丢失
This commit is contained in:
13
engine.go
13
engine.go
@@ -1,6 +1,7 @@
|
||||
package utpl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gitea.1216.top/lxy/u-tpl/internal"
|
||||
@@ -114,8 +115,16 @@ func wrapParseError(err error, name string) error {
|
||||
if _, ok := err.(*ParseError); ok {
|
||||
return err
|
||||
}
|
||||
msg := fmt.Sprintf("template %q: %s", name, err.Error())
|
||||
var posErr *internal.PosError
|
||||
if errors.As(err, &posErr) {
|
||||
return &ParseError{
|
||||
Pos: Position{Line: posErr.Line, Column: posErr.Col},
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
return &ParseError{
|
||||
Pos: Position{Line: 0, Column: 0},
|
||||
Message: fmt.Sprintf("template %q: %s", name, err.Error()),
|
||||
Pos: Position{},
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user