diff --git a/pkg/sync/error.go b/pkg/sync/error.go index 803697a8..e64eed71 100644 --- a/pkg/sync/error.go +++ b/pkg/sync/error.go @@ -36,23 +36,27 @@ func (e *SyncError) Unwrap() error { // Error that can be directly attributed to incorrect/unsupported code type SyncPosError struct { - Inner error - Filename string - Line int - Col int + Inner error + Filename string + StartLine int + StartCol int + EndLine int + EndCol int } -func NewSyncPosError(inner error, filename string, line, col int) *SyncPosError { +func NewSyncPosError(inner error, filename string, startLine, startCol, endLine, endCol int) *SyncPosError { return &SyncPosError{ - Inner: inner, - Filename: filename, - Line: line, - Col: col, + Inner: inner, + Filename: filename, + StartLine: startLine, + StartCol: startCol, + EndLine: endLine, + EndCol: endCol, } } func (e *SyncPosError) Error() string { - return fmt.Sprintf("sync %s:%d:%d: %v", e.Filename, e.Line, e.Col, e.Inner) + return fmt.Sprintf("sync %s:%d:%d:%d:%d: %v", e.Filename, e.StartLine, e.StartCol, e.EndLine, e.EndCol, e.Inner) } func (e *SyncPosError) Unwrap() error { diff --git a/pkg/sync/golang.go b/pkg/sync/golang.go index 4f00e0b2..ad31b3fd 100644 --- a/pkg/sync/golang.go +++ b/pkg/sync/golang.go @@ -433,7 +433,7 @@ func (g *goSyncer) exprToValue(expr ast.Expr) (string, error) { case *ast.SelectorExpr: return strcase.ToSnake(v.Sel.Name), nil default: - return "", g.posErr(expr, "unsupported syntax") + return "", g.posErr(expr, "unsupported context key syntax") } } @@ -1195,8 +1195,9 @@ func (g *goSyncer) posErr(node ast.Node, err any) error { // This means there's an internal bug panic("invalid inner error type") } - p := g.fset.Position(node.Pos()) - return NewSyncPosError(inner, p.Filename, p.Line, p.Column) + startPos := g.fset.Position(node.Pos()) + endPos := g.fset.Position(node.End()) + return NewSyncPosError(inner, startPos.Filename, startPos.Line, startPos.Column, endPos.Line, endPos.Column) } func (g *goSyncer) structToMap(structType *ast.StructType) (map[string]string, error) { diff --git a/pkg/sync/ts.go b/pkg/sync/ts.go index b4b6b3f4..a7e1233b 100644 --- a/pkg/sync/ts.go +++ b/pkg/sync/ts.go @@ -87,18 +87,26 @@ func checkSyncTSError(output []byte) error { if strings.Contains(o, "404") && strings.Contains(o, syncTSExec) { return NoSyncTSError } - r := regexp.MustCompile("LekkoParseError: (.*):(\\d+):(\\d+) - (.*)") + r := regexp.MustCompile("LekkoParseError: (.*):(\\d+):(\\d+):(\\d+):(\\d+) - (.*)") matches := r.FindStringSubmatch(o) if matches == nil { return NewSyncError(errors.New(o)) } - line, err := strconv.Atoi(matches[2]) + startLine, err := strconv.Atoi(matches[2]) if err != nil { return NewSyncError(errors.New(o)) } - col, err := strconv.Atoi(matches[3]) + startCol, err := strconv.Atoi(matches[3]) if err != nil { return NewSyncError(errors.New(o)) } - return NewSyncPosError(errors.New(matches[4]), matches[1], line, col) + endLine, err := strconv.Atoi(matches[4]) + if err != nil { + return NewSyncError(errors.New(o)) + } + endCol, err := strconv.Atoi(matches[5]) + if err != nil { + return NewSyncError(errors.New(o)) + } + return NewSyncPosError(errors.New(matches[4]), matches[1], startLine, startCol, endLine, endCol) } diff --git a/proto/lekko/bff/v1beta1/bff.proto b/proto/lekko/bff/v1beta1/bff.proto index a1ec0098..9a02e02d 100644 --- a/proto/lekko/bff/v1beta1/bff.proto +++ b/proto/lekko/bff/v1beta1/bff.proto @@ -831,6 +831,14 @@ message SaveNativeLangResponse { string formatted = 2; } +message SaveNativeLangError { + string message = 1; + uint32 start_line = 2; + uint32 start_col = 3; + uint32 end_line = 4; + uint32 end_col = 5; +} + message ConvertRuleToStringRequest { lekko.rules.v1beta3.Rule rule = 1; }