修复: byte/rune 长度混淆及错误位置丢失

This commit is contained in:
2026-04-01 10:43:16 +08:00
parent 1b5b6aff8f
commit 2f9d81dc17
8 changed files with 603 additions and 93 deletions

View File

@@ -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,
}
}