Skip to content

Commit

Permalink
fix: lsp error not showing correct error level #1631 (#1671)
Browse files Browse the repository at this point in the history
fixes #1631 

ensures error level is preserved in the round trip to protobuf
conversion and back
  • Loading branch information
jonathanj-square authored Jun 6, 2024
1 parent c9a8561 commit 112c6a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions backend/schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (e Error) ToProto() *schemapb.Error {
Msg: e.Msg,
Pos: posToProto(e.Pos),
EndColumn: int64(e.EndColumn),
Level: levelToProto(e.Level),
}
}

Expand All @@ -38,6 +39,7 @@ func errorFromProto(e *schemapb.Error) *Error {
Pos: posFromProto(e.Pos),
Msg: e.Msg,
EndColumn: int(e.EndColumn),
Level: levelFromProto(e.Level),
}
}

Expand Down Expand Up @@ -111,8 +113,7 @@ func Wrapf(pos Position, endColumn int, err error, format string, args ...any) *
newEndColumn = endColumn
args = append(args, err)
}
e := Error{Msg: fmt.Sprintf(format, args...), Pos: newPos, EndColumn: newEndColumn}
return &e
return makeError(ERROR, newPos, newEndColumn, format, args...)
}

func SortErrorsByPosition(merr []*Error) {
Expand Down
12 changes: 12 additions & 0 deletions backend/schema/protobuf_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func posFromProto(pos *schemapb.Position) Position {
}
}

func levelFromProto(level schemapb.Error_ErrorLevel) ErrorLevel {
switch level {
case schemapb.Error_INFO:
return INFO
case schemapb.Error_WARN:
return WARN
case schemapb.Error_ERROR:
return ERROR
}
panic(fmt.Sprintf("unhandled ErrorLevel %v", level))
}

func declListToSchema(s []*schemapb.Decl) []Decl {
var out []Decl
for _, n := range s {
Expand Down
12 changes: 12 additions & 0 deletions backend/schema/protobuf_enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)

func levelToProto(level ErrorLevel) schemapb.Error_ErrorLevel {
switch level {
case INFO:
return schemapb.Error_INFO
case WARN:
return schemapb.Error_WARN
case ERROR:
return schemapb.Error_ERROR
}
panic(fmt.Sprintf("unhandled ErrorLevel %v", level))
}

func posToProto(pos Position) *schemapb.Position {
return &schemapb.Position{Line: int64(pos.Line), Column: int64(pos.Column), Filename: pos.Filename}
}
Expand Down
2 changes: 1 addition & 1 deletion buildengine/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func assertBuildProtoErrors(msgs ...string) assertion {

expected := make([]*schema.Error, 0, len(msgs))
for _, msg := range msgs {
expected = append(expected, &schema.Error{Msg: msg})
expected = append(expected, &schema.Error{Msg: msg, Level: schema.ERROR})
}

// normalize results
Expand Down

0 comments on commit 112c6a9

Please sign in to comment.