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

Add test for eval.TooManyArgError() #3520

Merged
merged 3 commits into from
May 18, 2024

Conversation

tchssk
Copy link
Member

@tchssk tchssk commented May 16, 2024

Related to #3512

@tchssk tchssk marked this pull request as ready for review May 16, 2024 14:57
Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I left a couple of comments that might be good to address, thank you!

@@ -99,6 +99,7 @@ func ResultType(identifier string, args ...any) *expr.ResultTypeExpr {
}
if len(args) > 2 {
eval.TooManyArgError()
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value returned by this function might be used to do validations later on so the idea is to not return nil as the validation code assumes there's always an expression (which could be invalid). So we shouldn't return here - or return a zero result expression.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already two lines that return nil in ResultType. Are these wrong?

goa/dsl/result_type.go

Lines 65 to 69 in 78b71ce

func ResultType(identifier string, args ...any) *expr.ResultTypeExpr {
if _, ok := eval.Current().(eval.TopExpr); !ok {
eval.IncompatibleDSL()
return nil
}

goa/dsl/result_type.go

Lines 109 to 116 in 78b71ce

for _, rt := range expr.Root.ResultTypes {
if re := rt.(*expr.ResultTypeExpr); re.Identifier == canonicalID {
eval.ReportError(
"result type %#v with canonical identifier %#v is defined twice",
identifier, canonicalID)
return nil
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, looks like Type can also return nil so this case is probably safe.

dsl/server.go Outdated
@@ -59,6 +59,7 @@ import (
func Server(name string, fn ...func()) *expr.ServerExpr {
if len(fn) > 1 {
eval.TooManyArgError()
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@raphael raphael merged commit 10e59a1 into goadesign:v3 May 18, 2024
11 checks passed
@tchssk tchssk deleted the eval-toomanyargerror-test branch May 19, 2024 14:57
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 this pull request may close these issues.

2 participants