From 112c6a9917309fec8cc3c4f918c606d6b6b15333 Mon Sep 17 00:00:00 2001 From: Jon Johnson <113393155+jonathanj-square@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:58:40 -0700 Subject: [PATCH] fix: lsp error not showing correct error level #1631 (#1671) fixes #1631 ensures error level is preserved in the round trip to protobuf conversion and back --- backend/schema/errors.go | 5 +++-- backend/schema/protobuf_dec.go | 12 ++++++++++++ backend/schema/protobuf_enc.go | 12 ++++++++++++ buildengine/build_test.go | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/backend/schema/errors.go b/backend/schema/errors.go index 9d50a8774d..851b8db4c6 100644 --- a/backend/schema/errors.go +++ b/backend/schema/errors.go @@ -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), } } @@ -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), } } @@ -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) { diff --git a/backend/schema/protobuf_dec.go b/backend/schema/protobuf_dec.go index eac216c617..ce73448a41 100644 --- a/backend/schema/protobuf_dec.go +++ b/backend/schema/protobuf_dec.go @@ -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 { diff --git a/backend/schema/protobuf_enc.go b/backend/schema/protobuf_enc.go index 039ff088ef..552bf93430 100644 --- a/backend/schema/protobuf_enc.go +++ b/backend/schema/protobuf_enc.go @@ -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} } diff --git a/buildengine/build_test.go b/buildengine/build_test.go index 40655d9614..863b9d4d3a 100644 --- a/buildengine/build_test.go +++ b/buildengine/build_test.go @@ -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