Merge pull request #189 from minrk/timeout-spawn-error

better error messages for spawn failure
This commit is contained in:
Min RK
2015-03-23 11:55:15 -07:00
5 changed files with 29 additions and 22 deletions

View File

@@ -22,6 +22,13 @@ from ..utils import url_path_join
# pattern for the authentication token header # pattern for the authentication token header
auth_header_pat = re.compile(r'^token\s+([^\s]+)$') auth_header_pat = re.compile(r'^token\s+([^\s]+)$')
# mapping of reason: reason_message
reasons = {
'timeout': "Failed to reach your server."
" Please try again later."
" Contact admin if the issue persists.",
'error': "Failed to start your server. Please contact admin.",
}
class BaseHandler(RequestHandler): class BaseHandler(RequestHandler):
"""Base Handler class with access to common methods and properties.""" """Base Handler class with access to common methods and properties."""
@@ -323,7 +330,7 @@ class BaseHandler(RequestHandler):
# construct the custom reason, if defined # construct the custom reason, if defined
reason = getattr(exception, 'reason', '') reason = getattr(exception, 'reason', '')
if reason: if reason:
status_message = reason message = reasons.get(reason, reason)
# build template namespace # build template namespace
ns = dict( ns = dict(

View File

@@ -348,10 +348,12 @@ class User(Base):
self.log.warn("{user}'s server failed to start in {s} seconds, giving up".format( self.log.warn("{user}'s server failed to start in {s} seconds, giving up".format(
user=self.name, s=spawner.start_timeout, user=self.name, s=spawner.start_timeout,
)) ))
e.reason = 'timeout'
else: else:
self.log.error("Unhandled error starting {user}'s server: {error}".format( self.log.error("Unhandled error starting {user}'s server: {error}".format(
user=self.name, error=e, user=self.name, error=e,
)) ))
e.reason = 'error'
try: try:
yield self.stop() yield self.stop()
except Exception: except Exception:
@@ -378,7 +380,9 @@ class User(Base):
http_timeout=spawner.http_timeout, http_timeout=spawner.http_timeout,
) )
) )
e.reason = 'timeout'
else: else:
e.reason = 'error'
self.log.error("Unhandled error waiting for {user}'s server to show up at {url}: {error}".format( self.log.error("Unhandled error waiting for {user}'s server to show up at {url}: {error}".format(
user=self.name, url=self.server.url, error=e, user=self.name, url=self.server.url, error=e,
)) ))

View File

@@ -54,7 +54,7 @@ class Spawner(LoggingConfigurable):
) )
http_timeout = Integer( http_timeout = Integer(
10, config=True, 30, config=True,
help="""Timeout (in seconds) before giving up on a spawned HTTP server help="""Timeout (in seconds) before giving up on a spawned HTTP server
Once a server has successfully been spawned, this is the amount of time Once a server has successfully been spawned, this is the amount of time

View File

@@ -10,7 +10,7 @@ div.ajax-error {
} }
div.error > h1 { div.error > h1 {
font-size: 500%; font-size: 300%;
line-height: normal; line-height: normal;
} }
@@ -19,8 +19,3 @@ div.error > p {
line-height: normal; line-height: normal;
} }
div.traceback-wrapper {
text-align: left;
max-width: 800px;
margin: auto;
}

View File

@@ -7,16 +7,17 @@
<div class="error"> <div class="error">
{% block h1_error %} {% block h1_error %}
<h1>{{status_code}} : {{status_message}}</h1> <h1>
{{status_code}} : {{status_message}}
</h1>
{% endblock h1_error %} {% endblock h1_error %}
{% block error_detail %} {% block error_detail %}
{% if message %} {% if message %}
<p>The error was:</p> <p>
<div class="traceback-wrapper"> {{message}}
<pre class="traceback">{{message}}</pre> </p>
</div>
{% endif %} {% endif %}
{% endblock %} {% endblock error_detail %}
</div> </div>
{% endblock %} {% endblock %}