Commit 62a8c420 by Julian Arni

Check for exceptions when rendering studio and students views.

        Otherwise it's possible to reach stuck states.
parent e825cfb1
...@@ -6,7 +6,7 @@ from django.conf import settings ...@@ -6,7 +6,7 @@ from django.conf import settings
from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from mitxmako.shortcuts import render_to_response from mitxmako.shortcuts import render_to_response, render_to_string
from xmodule_modifiers import replace_static_urls, wrap_xmodule from xmodule_modifiers import replace_static_urls, wrap_xmodule
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
...@@ -79,9 +79,18 @@ def preview_component(request, location): ...@@ -79,9 +79,18 @@ def preview_component(request, location):
# can bind to it correctly # can bind to it correctly
component.runtime.wrappers.append(partial(wrap_xmodule, 'xmodule_edit.html')) component.runtime.wrappers.append(partial(wrap_xmodule, 'xmodule_edit.html'))
try:
content = component.render('studio_view').content
# catch exceptions indiscriminately, since after this point they escape the
# dungeon and surface as uneditable, unsaveable, and undeletable
# component-goblins.
except Exception as exc: #pylint: disable=W0703
content = render_to_string('html_error.html', {'message': str(exc)})
return render_to_response('component.html', { return render_to_response('component.html', {
'preview': get_preview_html(request, component, 0), 'preview': get_preview_html(request, component, 0),
'editor': component.render('studio_view').content, 'editor': content
}) })
...@@ -157,4 +166,8 @@ def get_preview_html(request, descriptor, idx): ...@@ -157,4 +166,8 @@ def get_preview_html(request, descriptor, idx):
specified by the descriptor and idx. specified by the descriptor and idx.
""" """
module = load_preview_module(request, str(idx), descriptor) module = load_preview_module(request, str(idx), descriptor)
return module.render("student_view").content try:
content = module.render("student_view").content
except Exception as exc: #pylint: disable=W0703
content = render_to_string('html_error.html', {'message': str(exc)})
return content
<%! from django.utils.translation import ugettext as _ %>
<%! from django.core.urlresolvers import reverse %>
<%block name="bodyclass">error</%block>
<%block name="content">
<div class="error-prompt">
<h2 class="description">
${_("We're having trouble rendering your component.")}
</h2>
% if message:
<p class="description">
${_("Error message:")}
</p>
<span text-align="center" width="60%">
<pre class="description">
${message | h}
</pre>
</span>
% endif
</div>
</%block>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment