encore icon indicating copy to clipboard operation
encore copied to clipboard

Calls not being traced if validation fails

Open melkstam opened this issue 11 months ago • 0 comments

We've had a few cases where traces for calls would not show up, neither locally, encore or our own cloud. To the best of our understanding, it happens when an internal parameter validation function returns an error.

Here is an example which reproduces the issue. When calling hello.World with failValidation: true, the following app does not gets any traced logged.

package hello

import (
	"context"

	"encore.dev/beta/errs"
)

type WorldParams struct {
	FailValidation bool `json:"failValidation"`
}

type WorldResponse struct {
	Message string `json:"message"`
}

//encore:api public
func World(ctx context.Context, in *WorldParams) (*WorldResponse, error) {

	err := WorldInteral(ctx, &WorldInternalParams{
		FailValidation: in.FailValidation,
	})
	if err != nil {
		return nil, err
	}

	return &WorldResponse{Message: "Hello, encore!"}, nil
}

type WorldInternalParams struct {
	FailValidation bool `json:"failValidation"`
}

func (p *WorldInternalParams) Validate() error {
	if p.FailValidation {
		return &errs.Error{Code: errs.InvalidArgument}
	}
	return nil
}

// encore:api private
func WorldInteral(ctx context.Context, in *WorldInternalParams) error {
	return nil
}

melkstam avatar Mar 11 '24 15:03 melkstam