Skip to content

Commit

Permalink
Fix Error() method for exception types
Browse files Browse the repository at this point in the history
Summary: Implement a type alias workaround to be able to `fmt.Sprintf` a Thrift exception type without causing infinite recursion.

Reviewed By: leoleovich

Differential Revision: D45934359

fbshipit-source-id: 536b95ac4359b0bee500b78ffc2ee2725352586c
  • Loading branch information
echistyakov authored and facebook-github-bot committed May 17, 2023
1 parent 57df0a2 commit ebf3143
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ func (x *{{struct:go_name}}) String() string {
Error method.
Note: 'fmt' package calls Error() method when formatting objects which
implement error interface. This will result in infinite recursion and
stack overflow unless type aliasing is used (as done below).
}}{{#struct:exception?}}
func (x *{{struct:go_name}}) Error() string {
return x.String()
type {{struct:go_name}}Alias {{struct:go_name}}
valueAlias := (*{{struct:go_name}}Alias)(x)
return fmt.Sprintf("%+v", valueAlias)
}

{{/struct:exception?}}{{!
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ebf3143

Please sign in to comment.