Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move build errors out of schema #2945

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 308 additions & 0 deletions backend/protos/xyz/block/ftl/v1/language/language.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions backend/protos/xyz/block/ftl/v1/language/language.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";

package xyz.block.ftl.v1.language;

import "xyz/block/ftl/v1/schema/schema.proto";

option go_package = "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/language;languagepb";
option java_multiple_files = true;

message Error {
enum ErrorLevel {
INFO = 0;
WARN = 1;
ERROR = 2;
}

string msg = 1;
schema.Position pos = 2;
int64 endColumn = 3;
ErrorLevel level = 4;
}

message ErrorList {
repeated Error errors = 1;
}
64 changes: 64 additions & 0 deletions backend/protos/xyz/block/ftl/v1/language/mixins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package languagepb

import (
"fmt"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/builderrors"
"github.com/TBD54566975/ftl/internal/slices"
)

// ErrorsFromProto converts a protobuf ErrorList to a []builderrors.Error.
func ErrorsFromProto(e *ErrorList) []builderrors.Error {
return slices.Map(e.Errors, errorFromProto)
}

func ErrorsToProto(errs []builderrors.Error) *ErrorList {
return &ErrorList{Errors: slices.Map(errs, errorToProto)}
}

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

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

func errorFromProto(e *Error) builderrors.Error {
return builderrors.Error{
Pos: schema.PosFromProto(e.Pos).ToErrorPosWithEnd(int(e.EndColumn)),
Msg: e.Msg,
Level: levelFromProto(e.Level),
}
}

func errorToProto(e builderrors.Error) *Error {
return &Error{
Msg: e.Msg,
Pos: &schemapb.Position{
Filename: e.Pos.Filename,
Column: int64(e.Pos.StartColumn),
Line: int64(e.Pos.Line),
},
EndColumn: int64(e.Pos.EndColumn),
Level: levelToProto(e.Level),
}
}
Loading
Loading