From fbc4fc684603098bf5904b892e271a8041e38b41 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 8 Jul 2019 14:28:56 -0400 Subject: [PATCH] Make unexpected error more specific Often a usable summary message is obfuscated. Assume the subject line is safe to relay, but continue to do a more verbose trace. --- confluent_client/bin/confetty | 9 +++++++++ confluent_server/confluent/httpapi.py | 6 +++--- confluent_server/confluent/sockapi.py | 8 ++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 951b1998..277384d2 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -504,6 +504,13 @@ def makecall(callout, args): if 'errorcode' in response: exitcode = response['errorcode'] sys.stderr.write('Error: ' + response['error'] + '\n') + if 'databynode' in response: + lresponse = response['databynode'] + for node in lresponse: + if 'errorcode' in lresponse[node]: + exitcode = lresponse[node]['errorcode'] + if 'error' in lresponse[node]: + sys.stderr.write('{0}: Error - {1}\n'.format(node, lresponse[node]['error'])) def clearvalues(resource, attribs): @@ -997,4 +1004,6 @@ if __name__ == '__main__': if deadline and os.times()[4] < deadline: sys.stderr.write('[Exited early, hit enter to continue]') sys.stdin.readline() + if errcode == 0: + errcode = exitcode sys.exit(errcode) diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index 3ef60010..bf7176e5 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -384,11 +384,11 @@ def resourcehandler(env, start_response): try: for rsp in resourcehandler_backend(env, start_response): yield rsp - except: + except Exception as e: tracelog.log(traceback.format_exc(), ltype=log.DataTypes.event, event=log.Events.stacktrace) - start_response('500 - Internal Server Error', []) - yield '500 - Internal Server Error' + start_response('500 - ' + str(e), []) + yield '500 - ' + str(e) return diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index 6c181a4e..d4382814 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -182,11 +182,11 @@ def sessionhdl(connection, authname, skipauth=False, cert=None): send_data(connection, {'_requestdone': 1}) except SystemExit: sys.exit(0) - except: + except Exception as e: tracelog.log(traceback.format_exc(), ltype=log.DataTypes.event, event=log.Events.stacktrace) send_data(connection, {'errorcode': 500, - 'error': 'Unexpected error'}) + 'error': 'Unexpected error - ' + str(e)}) send_data(connection, {'_requestdone': 1}) request = tlvdata.recv(connection) @@ -313,12 +313,12 @@ def term_interact(authdata, authname, ccons, cfm, connection, consession, try: process_request(connection, data, cfm, authdata, authname, skipauth) - except Exception: + except Exception as e: tracelog.log(traceback.format_exc(), ltype=log.DataTypes.event, event=log.Events.stacktrace) send_data(connection, {'errorcode': 500, - 'error': 'Unexpected error'}) + 'error': 'Unexpected error - ' + str(e)}) send_data(connection, {'_requestdone': 1}) continue if not data: