summaryrefslogtreecommitdiff
path: root/sphinx/directives/code.py
diff options
context:
space:
mode:
authorRam Rachum <ram@rachum.com>2020-06-11 20:23:35 +0300
committerRam Rachum <ram@rachum.com>2020-06-12 18:53:45 +0300
commit5ad6f3775754764f3dedda6955630c3b781d4f60 (patch)
treedd844bf1058da2bdd5bb6aed414f543dff7e7121 /sphinx/directives/code.py
parent9df73e65b8b2fc7836bf4a4baf1851b30c138d7d (diff)
downloadsphinx-git-5ad6f3775754764f3dedda6955630c3b781d4f60.tar.gz
Fix exception causes in code.py
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r--sphinx/directives/code.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index 8c19dd0c5..f1f4a341a 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -227,12 +227,13 @@ class LiteralIncludeReader:
text = text.expandtabs(self.options['tab-width'])
return text.splitlines(True)
- except OSError:
- raise OSError(__('Include file %r not found or reading it failed') % filename)
- except UnicodeError:
+ except OSError as exc:
+ raise OSError(__('Include file %r not found or reading it failed') %
+ filename) from exc
+ except UnicodeError as exc:
raise UnicodeError(__('Encoding %r used for reading included file %r seems to '
'be wrong, try giving an :encoding: option') %
- (self.encoding, filename))
+ (self.encoding, filename)) from exc
def read(self, location: Tuple[str, int] = None) -> Tuple[str, int]:
if 'diff' in self.options: