From fe3ae5747592ca85a656f4948d0cd36c98036a1e Mon Sep 17 00:00:00 2001 From: Jon Johnson <113393155+jonathanj-square@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:50:00 -0700 Subject: [PATCH] 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 +- go-runtime/compile/testdata/validation/go.sum | 12 ++++++++---- 5 files changed, 36 insertions(+), 7 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 diff --git a/go-runtime/compile/testdata/validation/go.sum b/go-runtime/compile/testdata/validation/go.sum index 03d1ea2819..d4b84ece19 100644 --- a/go-runtime/compile/testdata/validation/go.sum +++ b/go-runtime/compile/testdata/validation/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= @@ -122,14 +126,14 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI= modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= -modernc.org/libc v1.49.3 h1:j2MRCRdwJI2ls/sGbeSk0t2bypOG/uvPZUsGQFDulqg= -modernc.org/libc v1.49.3/go.mod h1:yMZuGkn7pXbKfoT/M35gFJOAEdSKdxL0q64sF7KqCDo= +modernc.org/libc v1.50.9 h1:hIWf1uz55lorXQhfoEoezdUHjxzuO6ceshET/yWjSjk= +modernc.org/libc v1.50.9/go.mod h1:15P6ublJ9FJR8YQCGy8DeQ2Uwur7iW9Hserr/T3OFZE= modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= -modernc.org/sqlite v1.29.10 h1:3u93dz83myFnMilBGCOLbr+HjklS6+5rJLx4q86RDAg= -modernc.org/sqlite v1.29.10/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA= +modernc.org/sqlite v1.30.0 h1:8YhPUs/HTnlEgErn/jSYQTwHN/ex8CjHHjg+K9iG7LM= +modernc.org/sqlite v1.30.0/go.mod h1:cgkTARJ9ugeXSNaLBPK3CqbOe7Ec7ZhWPoMFGldEYEw= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=