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 nil check for user type in gen_app #1073

Merged
merged 4 commits into from
Feb 25, 2017
Merged

Conversation

tchssk
Copy link
Member

@tchssk tchssk commented Feb 24, 2017

Fix #1060.

@tchssk
Copy link
Member Author

tchssk commented Feb 24, 2017

Would you try this to your project? @luna-duclos

@luna-duclos
Copy link

Just tested this, code looks good, and code works! 👍

@raphael
Copy link
Member

raphael commented Feb 24, 2017

Thank you for the great PR with additional tests! I am wondering though if it wouldn't be better to put the test in the caller (https://github.com/goadesign/goa/blob/master/goagen/codegen/publicizer.go#L130) rather than in the Publicize function itself. Publicize should not be called on nil and protecting against that could hide other bugs (where the target should not have been nil but was because of a bug).

@luna-duclos
Copy link

I think a function not blowing up on nil is generally good behaviour. I can see your point about masking other bugs however, but considering these bugs would usually be the same nil check .. I don't see the harm

@raphael
Copy link
Member

raphael commented Feb 24, 2017

For example you may end up with code that is generated fine but does not compile because the Publicize method is missing. This is a lot harder to track than a clear error such as the one you hit where it took me 10 seconds to find the offending line. In general I dislike the idea of writing defensive code "just because" - it makes tracking issues down the line orders of magnitude more difficult.

@tchssk
Copy link
Member Author

tchssk commented Feb 25, 2017

I reverted the commit and moved nil check to publicizer for hash. Is it correct?

@raphael
Copy link
Member

raphael commented Feb 25, 2017

Yes perfect, thank you for making the change!

@raphael raphael merged commit 934c228 into goadesign:master Feb 25, 2017
raphael pushed a commit that referenced this pull request Mar 1, 2017
* Add tests for UserTypeWriter in gen_app

* Add nil check for user type in gen_app

* Revert "Add nil check for user type in gen_app"

This reverts commit ecf0f68.

* Add nil check in publicizer for hash
raphael pushed a commit that referenced this pull request Mar 1, 2017
* Add tests for UserTypeWriter in gen_app

* Add nil check for user type in gen_app

* Revert "Add nil check for user type in gen_app"

This reverts commit ecf0f68.

* Add nil check in publicizer for hash
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.

3 participants