From 033f922ec03f8323f44380e653ab1b867e9947a0 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Sat, 17 Aug 2013 10:15:03 -0400 Subject: [PATCH] add a try catch around the staticstorage lookup, which can throw an exception --- common/djangoapps/static_replace/__init__.py | 11 +++++++++- common/test/data/toy/course/2012_Fall.xml | 1 + common/test/data/toy/html/badlink.html | 1 + common/test/data/toy/html/badlink.xml | 1 + .../courseware/tests/test_module_render.py | 21 ++++++++++++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 common/test/data/toy/html/badlink.html create mode 100644 common/test/data/toy/html/badlink.xml diff --git a/common/djangoapps/static_replace/__init__.py b/common/djangoapps/static_replace/__init__.py index 63c576cdd2..d7f2df8322 100644 --- a/common/djangoapps/static_replace/__init__.py +++ b/common/djangoapps/static_replace/__init__.py @@ -119,7 +119,15 @@ def replace_static_urls(text, data_directory, course_id=None): elif course_id and modulestore().get_modulestore_type(course_id) != XML_MODULESTORE_TYPE: # first look in the static file pipeline and see if we are trying to reference # a piece of static content which is in the mitx repo (e.g. JS associated with an xmodule) - if staticfiles_storage.exists(rest): + + exists_in_staticfiles_storage = False + try: + exists_in_staticfiles_storage = staticfiles_storage.exists(rest) + except Exception as err: + log.warning("staticfiles_storage couldn't find path {0}: {1}".format( + rest, str(err))) + + if exists_in_staticfiles_storage: url = staticfiles_storage.url(rest) else: # if not, then assume it's courseware specific content and then look in the @@ -142,6 +150,7 @@ def replace_static_urls(text, data_directory, course_id=None): return "".join([quote, url, quote]) + return re.sub( _url_replace_regex('/static/(?!{data_dir})'.format(data_dir=data_directory)), replace_static_url, diff --git a/common/test/data/toy/course/2012_Fall.xml b/common/test/data/toy/course/2012_Fall.xml index 9b14d49dcd..ec75ef0b9d 100644 --- a/common/test/data/toy/course/2012_Fall.xml +++ b/common/test/data/toy/course/2012_Fall.xml @@ -7,6 +7,7 @@ +