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

Cannot return an escaped string or json as field value in a verb response struct #1199

Closed
mistermoe opened this issue Apr 8, 2024 · 1 comment · Fixed by #1203
Closed
Assignees

Comments

@mistermoe
Copy link
Member

Repro

offerings.go

package offerings

import (
	"context"
	"ftl/builtin"

	"ftl/rates"

	"github.com/TBD54566975/ftl/go-runtime/ftl"
)

type ApiError struct {
	Error string `json:"error"`
}

//ftl:export
//ftl:ingress GET /offerings
func GetOfferings(ctx context.Context, req builtin.HttpRequest[builtin.Empty]) (builtin.HttpResponse[builtin.Empty, ApiError], error) {
	log := ftl.LoggerFromContext(ctx)
	rate, err := ftl.Call(ctx, rates.GetRates, rates.RateRequest{})
	log.Infof("RATE! %v", rate)

	if err != nil {
		return builtin.HttpResponse[builtin.Empty, ApiError]{
			Status: 500,
			Error:  ftl.Some(ApiError{Error: "wottf"}),
		}, nil
	}

	return builtin.HttpResponse[builtin.Empty, ApiError]{
		Status: 200,
		Body:   ftl.Some(builtin.Empty{}),
	}, nil
}

rates.go

package rates

import (
	"context"
)

type RateRequest struct{}

type RateResponse struct {
	Rates string `json:"rates"`
}

//ftl:export
func GetRates(ctx context.Context, req RateRequest) (RateResponse, error) {
	return RateResponse{
		Rates: `"hi2u"`,
	}, nil
}
❯ curl -v 'http://localhost:8892/ingress/offerings'
*   Trying [::1]:8892...
* connect to ::1 port 8892 failed: Connection refused
*   Trying 127.0.0.1:8892...
* Connected to localhost (127.0.0.1) port 8892
> GET /ingress/offerings HTTP/1.1
> Host: localhost:8892
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Mon, 08 Apr 2024 04:43:58 GMT
< Content-Length: 17
<
* Connection #0 to host localhost left intact
{"error":"wottf"}

terminal running ftl dev:

error:controller0: failed to record call: ERROR: invalid input syntax for type json (SQLSTATE 22P02)
info:ledger: RATE! {}

Other Thoughts

@alecthomas
Copy link
Collaborator

Found what is happening. The response is:

{"rates":""hi2u""}

@alecthomas alecthomas self-assigned this Apr 8, 2024
@github-actions github-actions bot removed the triage Issue needs triaging label Apr 8, 2024
alecthomas added a commit that referenced this issue Apr 8, 2024
alecthomas added a commit that referenced this issue Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants