Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
0c82bae9
Commit
0c82bae9
authored
Apr 12, 2017
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the caller to user_api caught error logging
parent
4d21fbe6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
openedx/core/djangoapps/user_api/helpers.py
+6
-2
openedx/core/djangoapps/user_api/tests/test_helpers.py
+18
-4
No files found.
openedx/core/djangoapps/user_api/helpers.py
View file @
0c82bae9
...
...
@@ -6,6 +6,7 @@ from collections import defaultdict
from
functools
import
wraps
import
logging
import
json
import
traceback
from
django
import
forms
from
django.core.serializers.json
import
DjangoJSONEncoder
...
...
@@ -65,16 +66,19 @@ def intercept_errors(api_error, ignore_errors=None):
LOGGER
.
warning
(
msg
)
raise
caller
=
traceback
.
format_stack
(
limit
=
2
)[
0
]
# Otherwise, log the error and raise the API-specific error
msg
=
(
u"An unexpected error occurred when calling '{func_name}' "
u"with arguments '{args}' and keyword arguments '{kwargs}': "
u"with arguments '{args}' and keyword arguments '{kwargs}'
from {caller}
: "
u"{exception}"
)
.
format
(
func_name
=
func
.
func_name
,
args
=
args
,
kwargs
=
kwargs
,
exception
=
ex
.
developer_message
if
hasattr
(
ex
,
'developer_message'
)
else
repr
(
ex
)
exception
=
ex
.
developer_message
if
hasattr
(
ex
,
'developer_message'
)
else
repr
(
ex
),
caller
=
caller
.
strip
()
)
LOGGER
.
exception
(
msg
)
raise
api_error
(
msg
)
...
...
openedx/core/djangoapps/user_api/tests/test_helpers.py
View file @
0c82bae9
...
...
@@ -2,6 +2,7 @@
Tests for helper functions.
"""
import
json
import
re
import
mock
import
ddt
from
django
import
forms
...
...
@@ -52,22 +53,35 @@ class InterceptErrorsTest(TestCase):
@mock.patch
(
'openedx.core.djangoapps.user_api.helpers.LOGGER'
)
def
test_logs_errors
(
self
,
mock_logger
):
self
.
maxDiff
=
None
exception
=
'openedx.core.djangoapps.user_api.tests.test_helpers.FakeInputException'
expected_log_msg
=
(
u"An unexpected error occurred when calling 'intercepted_function' with arguments '()' and "
u"keyword arguments '{'raise_error': <class '"
+
exception
+
u"'>}': FakeInputException()"
)
u"keyword arguments '{{'raise_error': <class '{}'>}}' "
u"from File
\"
{}
\"
, line XXX, in test_logs_errors
\n
"
u" intercepted_function(raise_error=FakeInputException): FakeInputException()"
)
.
format
(
exception
,
__file__
)
# Verify that the raised exception has the error message
try
:
intercepted_function
(
raise_error
=
FakeInputException
)
except
FakeOutputException
as
ex
:
self
.
assertEqual
(
ex
.
message
,
expected_log_msg
)
actual_message
=
re
.
sub
(
r'line \d+'
,
'line XXX'
,
ex
.
message
,
flags
=
re
.
MULTILINE
)
self
.
assertEqual
(
actual_message
,
expected_log_msg
)
# Verify that the error logger is called
# This will include the stack trace for the original exception
# because it's called with log level "ERROR"
mock_logger
.
exception
.
assert_called_once_with
(
expected_log_msg
)
calls
=
mock_logger
.
exception
.
mock_calls
self
.
assertEqual
(
len
(
calls
),
1
)
name
,
args
,
kwargs
=
calls
[
0
]
self
.
assertEqual
(
name
,
''
)
self
.
assertEqual
(
len
(
args
),
1
)
self
.
assertEqual
(
kwargs
,
{})
actual_message
=
re
.
sub
(
r'line \d+'
,
'line XXX'
,
args
[
0
],
flags
=
re
.
MULTILINE
)
self
.
assertEqual
(
actual_message
,
expected_log_msg
)
class
FormDescriptionTest
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment