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

Fix errors output #243

Merged
merged 3 commits into from
Jun 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add support for new model interface [#229](https://github.com/gohypermode/runtime/pull/229)
- Add sequential vector search [#240](https://github.com/hypermodeAI/runtime/pull/240)
- Update Hypermode-hosted model endpoint URL [#242](https://github.com/gohypermode/runtime/pull/242)
- Fix bug caused by #226 [#243](https://github.com/gohypermode/runtime/pull/243)

## 2024-06-03 - Version 0.8.2

Expand Down
22 changes: 6 additions & 16 deletions graphql/datasource/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ type callInfo struct {
Parameters map[string]any `json:"data"`
}

type FunctionOutput struct {
ExecutionId string
Buffers utils.OutputBuffers
}

type Source struct{}

func (s Source) Load(ctx context.Context, input []byte, writer io.Writer) error {
Expand All @@ -57,19 +52,14 @@ func (s Source) Load(ctx context.Context, input []byte, writer io.Writer) error
func (s Source) callFunction(ctx context.Context, callInfo callInfo) (any, []resolve.GraphQLError, error) {
// Call the function
info, err := wasmhost.CallFunctionWithParametersMap(ctx, callInfo.Function.Name, callInfo.Parameters)
if err != nil {
return nil, nil, err
}
// NOTE: don't return the error here, as we want to capture function errors in the response.

// Store the Execution ID and output buffers in the context
outputMap := ctx.Value(utils.FunctionOutputContextKey).(map[string]FunctionOutput)
outputMap[callInfo.Function.AliasOrName()] = FunctionOutput{
ExecutionId: info.ExecutionId,
Buffers: *info.Buffers,
}
// Store the execution info into the function output map.
outputMap := ctx.Value(utils.FunctionOutputContextKey).(map[string]*wasmhost.ExecutionInfo)
outputMap[callInfo.Function.AliasOrName()] = info

// Transform messages (and error lines in the output buffers) to GraphQL errors
messages := append(info.Messages, utils.TransformConsoleOutput(*info.Buffers)...)
// Transform messages (and error lines in the output buffers) to GraphQL errors.
messages := append(info.Messages, utils.TransformConsoleOutput(info.Buffers)...)
gqlErrors := transformErrors(messages, callInfo)

return info.Result, gqlErrors, err
Expand Down
6 changes: 3 additions & 3 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"fmt"
"net/http"

"hmruntime/graphql/datasource"
"hmruntime/graphql/engine"
"hmruntime/logger"
"hmruntime/pluginmanager"
"hmruntime/utils"
"hmruntime/wasmhost"

"github.com/buger/jsonparser"
eng "github.com/wundergraph/graphql-go-tools/execution/engine"
Expand Down Expand Up @@ -57,7 +57,7 @@ func HandleGraphQLRequest(w http.ResponseWriter, r *http.Request) {
}

// Create the output map
output := map[string]datasource.FunctionOutput{}
output := map[string]*wasmhost.ExecutionInfo{}
ctx = context.WithValue(ctx, utils.FunctionOutputContextKey, output)

// Set tracing options
Expand Down Expand Up @@ -111,7 +111,7 @@ func HandleGraphQLRequest(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(response)
}

func addOutputToResponse(response []byte, output map[string]datasource.FunctionOutput) ([]byte, error) {
func addOutputToResponse(response []byte, output map[string]*wasmhost.ExecutionInfo) ([]byte, error) {

type invocationInfo struct {
ExecutionId string `json:"executionId"`
Expand Down
2 changes: 1 addition & 1 deletion utils/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (l LogMessage) IsError() bool {
return l.Level == "error" || l.Level == "fatal"
}

func TransformConsoleOutput(buffers OutputBuffers) []LogMessage {
func TransformConsoleOutput(buffers *OutputBuffers) []LogMessage {
return append(transformConsoleOutputLines(&buffers.StdOut), transformConsoleOutputLines(&buffers.StdErr)...)
}

Expand Down