Skip to content

Commit

Permalink
refactor: move schema errors out of schema
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 2, 2024
1 parent 8538155 commit 225d7e2
Show file tree
Hide file tree
Showing 25 changed files with 1,554 additions and 1,434 deletions.
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

0 comments on commit 225d7e2

Please sign in to comment.