generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move schema errors out of schema
- Loading branch information
Showing
25 changed files
with
1,554 additions
and
1,434 deletions.
There are no files selected for viewing
308 changes: 308 additions & 0 deletions
308
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
Oops, something went wrong.