Skip to content

Commit 67bf304

Browse files
committed
THRIFT-5459: Fix breaking issue when adding a new exception
Client: go Currently in the compiler generated go code, adding a new exception to an existing endpoint can cause unexpected behaviors when the client isn't updated. Fix the issue. Will be cherry-picked into 0.15.0 after merged.
1 parent 5f829f1 commit 67bf304

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
- [THRIFT-5404](https://issues.apache.org/jira/browse/THRIFT-5404) - TTransportException.Timeout would correctly return true when it's connect timeout during TSocket.Open call
8282
- [THRIFT-4797](https://issues.apache.org/jira/browse/THRIFT-4797) - The compiler now correctly auto renames import thrift namespaces when they collide with system imports
8383
- [THRIFT-5453](https://issues.apache.org/jira/browse/THRIFT-5453) - Defer DNS lookups from NewTSocketConf (without any timeout check) to TSocket.Open (subject to ConnectTimeout set in TConfiguration)
84+
- [THRIFT-5459](https://issues.apache.org/jira/browse/THRIFT-5459) - Client calls will return TApplicationException with MISSING_RESULT when the result is a struct but is unset, and no other error is known.
8485

8586
### Haskell
8687

compiler/cpp/src/thrift/generate/t_go_generator.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,23 @@ void t_go_generator::generate_service_client(t_service* tservice) {
22952295
f_types_ << indent() << "}" << endl << endl;
22962296
}
22972297

2298-
if (!(*f_iter)->get_returntype()->is_void()) {
2298+
if ((*f_iter)->get_returntype()->is_struct()) {
2299+
// Check if the result is nil, which likely means we have a new
2300+
// exception added but unknown to the client yet
2301+
// (e.g. client hasn't updated the thrift file).
2302+
// Sadly this check can only be reliable done when the return type is a
2303+
// struct in go.
2304+
std::string retName = tmp("_ret");
2305+
f_types_ << indent() << "if " << retName << " := " << resultName
2306+
<< ".GetSuccess(); " << retName << " != nil {" << endl;
2307+
indent_up();
2308+
f_types_ << indent() << "return " << retName << ", nil" << endl;
2309+
indent_down();
2310+
f_types_ << indent() << "}" << endl;
2311+
f_types_ << indent() << "return nil, "
2312+
<< "thrift.NewTApplicationException(thrift.MISSING_RESULT, \""
2313+
<< method << " failed: unknown result\")" << endl;
2314+
} else if (!(*f_iter)->get_returntype()->is_void()) {
22992315
f_types_ << indent() << "return " << resultName << ".GetSuccess(), nil" << endl;
23002316
} else {
23012317
f_types_ << indent() << "return nil" << endl;

0 commit comments

Comments
 (0)