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.
fix(go-runtime): remove duplicate positional information in errors (#…
- Loading branch information
1 parent
0e4ea0a
commit 4221f57
Showing
4 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
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,40 @@ | ||
package compile | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"go/ast" | ||
|
||
"github.com/TBD54566975/ftl/backend/schema" | ||
) | ||
|
||
type Error struct { | ||
Msg string | ||
Pos schema.Position | ||
Err error // Wrapped error, if any | ||
} | ||
|
||
func (e Error) Error() string { return fmt.Sprintf("%s: %s", e.Pos, e.Msg) } | ||
func (e Error) Unwrap() error { return e.Err } | ||
|
||
func errorf(node ast.Node, format string, args ...any) Error { | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: goPosToSchemaPos(node.Pos())} | ||
} | ||
|
||
func wrapf(node ast.Node, err error, format string, args ...any) Error { | ||
if format == "" { | ||
format = "%s" | ||
} else { | ||
format += ": %s" | ||
} | ||
// Propagate existing error position if available | ||
var pos schema.Position | ||
if perr := (Error{}); errors.As(err, &perr) { | ||
pos = perr.Pos | ||
args = append(args, perr.Msg) | ||
} else { | ||
pos = goPosToSchemaPos(node.Pos()) | ||
args = append(args, err) | ||
} | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: pos, Err: err} | ||
} |
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
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
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,17 @@ | ||
//ftl:module failing | ||
package failing | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TBD54566975/ftl/go-runtime/ftl" | ||
) | ||
|
||
type Request struct{} | ||
type Response struct{} | ||
|
||
//ftl:verb | ||
func FailingVerb(ctx context.Context, req Request) (Response, error) { | ||
ftl.Call(ctx, "failing", "failingVerb", req) | ||
return Response{}, nil | ||
} |