Skip to content

Commit

Permalink
fix: language plugins should always include an error with level=ERROR…
Browse files Browse the repository at this point in the history
… for BuildFailure (#3296)

Otherwise `buildengine` tries to read a nil schema value leading to a
crash
  • Loading branch information
matt2e authored Nov 1, 2024
1 parent 61731fd commit 21d6bf3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions go-runtime/goplugin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ func build(ctx context.Context, projectRoot, stubsRoot string, buildCtx buildCon
m, buildErrs, err := compile.Build(ctx, projectRoot, stubsRoot, buildCtx.Config, buildCtx.Schema, transaction, false)
if err != nil {
return buildFailure(buildCtx, isAutomaticRebuild, builderrors.Error{
Type: builderrors.FTL,
Level: builderrors.ErrorLevel(builderrors.COMPILER),
Type: builderrors.COMPILER,
Level: builderrors.ERROR,
Msg: "compile: " + err.Error(),
}), nil
}
Expand Down
11 changes: 11 additions & 0 deletions internal/buildengine/languageplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,17 @@ func buildResultFromProto(result either.Either[*langpb.BuildEvent_BuildSuccess,

errs := langpb.ErrorsFromProto(buildFailure.Errors)
builderrors.SortErrorsByPosition(errs)

if !builderrors.ContainsTerminalError(errs) {
// This happens if the language plugin returns BuildFailure but does not include any errors with level ERROR.
// Language plugins should always include at least one error with level ERROR in the case of a build failure.
errs = append(errs, builderrors.Error{
Msg: "unexpected build failure without error level ERROR",
Level: builderrors.ERROR,
Type: builderrors.FTL,
})
}

return BuildResult{
Errors: errs,
InvalidateDependencies: buildFailure.InvalidateDependencies,
Expand Down
3 changes: 2 additions & 1 deletion internal/buildengine/languageplugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ func buildEventWithBuildError(contextID string, isAutomaticRebuild bool, msg str
IsAutomaticRebuild: isAutomaticRebuild,
Errors: langpb.ErrorsToProto([]builderrors.Error{
{
Msg: msg,
Msg: msg,
Level: builderrors.ERROR,
},
}),
},
Expand Down

0 comments on commit 21d6bf3

Please sign in to comment.