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