Skip to content

Commit

Permalink
Fix protocol breakage on top-level server failures (#683).
Browse files Browse the repository at this point in the history
  • Loading branch information
spyysalo committed Feb 17, 2012
1 parent bda8711 commit 62754d4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions server/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@


class PermissionError(Exception):
pass
def json(self, json_dic):
json_dic['exception'] = 'permissionError'

class ConfigurationError(Exception):
def json(self, json_dic):
json_dic['exception'] = 'configurationError'


# TODO: Possibly check configurations too
Expand All @@ -59,10 +64,6 @@ def _permission_check():
raise PermissionError


class ConfigurationError(Exception):
pass


# Error message template functions
def _miss_var_msg(var):
return ('Missing variable "%s" in %s, make sure that you have '
Expand Down Expand Up @@ -258,7 +259,7 @@ def _server_crash(cookie_hdrs, e):
print >> stderr, stack_trace

json_dic = {
'exception': True,
'exception': 'serverCrash',
}
return (cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(json_dic))))

Expand Down Expand Up @@ -293,15 +294,17 @@ def serve(params, client_ip, client_hostname, cookie_data):
# can thus manipulate each other's global variables
with CONFIG_CHECK_LOCK:
_config_check()
except ConfigurationError:
return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json({})))
except ConfigurationError, e:
exception_json = e.json()
return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(exception_json)))
# We can now safely read the config
from config import DEBUG

try:
_permission_check()
except PermissionError:
return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json({})))
except PermissionError, e:
exception_json = e.json()
return cookie_hdrs, ((JSON_HDR, ), dumps(Messager.output_json(exception_json)))

try:
# Safe region, can throw any exception, has verified installation
Expand Down

0 comments on commit 62754d4

Please sign in to comment.