diff --git a/sphinxcontrib/datatemplates/directive.py b/sphinxcontrib/datatemplates/directive.py index adfd700..53336f5 100644 --- a/sphinxcontrib/datatemplates/directive.py +++ b/sphinxcontrib/datatemplates/directive.py @@ -1,5 +1,6 @@ import codecs import csv +import dbm import json import mimetypes from collections import defaultdict @@ -214,7 +215,11 @@ def run(self): nodes.literal_block(self.block_text, self.block_text), line=self.lineno) return [error] - except (json.decoder.JSONDecodeError, ET.ParseError) as err: + except ( + json.decoder.JSONDecodeError, + ET.ParseError, + dbm.error[0], + ) as err: error = self.state_machine.reporter.error( f"Error in source file '{relative_resolved_path}': {err}", nodes.literal_block(self.block_text, self.block_text), diff --git a/tests/test_errors.py b/tests/test_errors.py index 7d47e4c..467cdd3 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -112,3 +112,14 @@ def test_incorrect_import_module(app: SphinxTestApp, warning: StringIO): "ERROR: Source module 'some_module' not found" ) assert expected_error_str in warning.getvalue() + + +@pytest.mark.sphinx("html", testroot="incorrect-dbm") +def test_incorrect_dbm(app: SphinxTestApp, warning: StringIO): + app.builder.build_all() + expected_error_str = ( + f"{app.srcdir / 'index.rst'}:1: " + "ERROR: Error in source file 'sampledbm': " + "db type could not be determined" + ) + assert expected_error_str in warning.getvalue() diff --git a/tests/testdata/test-incorrect-dbm/conf.py b/tests/testdata/test-incorrect-dbm/conf.py new file mode 100644 index 0000000..8090b56 --- /dev/null +++ b/tests/testdata/test-incorrect-dbm/conf.py @@ -0,0 +1,2 @@ +extensions = ["sphinxcontrib.datatemplates"] +templates_path = ["templates"] diff --git a/tests/testdata/test-incorrect-dbm/index.rst b/tests/testdata/test-incorrect-dbm/index.rst new file mode 100644 index 0000000..cca3313 --- /dev/null +++ b/tests/testdata/test-incorrect-dbm/index.rst @@ -0,0 +1,2 @@ +.. datatemplate:dbm:: sampledbm + :template: sample.tmpl diff --git a/tests/testdata/test-incorrect-dbm/sampledbm b/tests/testdata/test-incorrect-dbm/sampledbm new file mode 100644 index 0000000..679aa53 --- /dev/null +++ b/tests/testdata/test-incorrect-dbm/sampledbm @@ -0,0 +1 @@ +sample text \ No newline at end of file diff --git a/tests/testdata/test-incorrect-dbm/templates/sample.tmpl b/tests/testdata/test-incorrect-dbm/templates/sample.tmpl new file mode 100644 index 0000000..367d1bb --- /dev/null +++ b/tests/testdata/test-incorrect-dbm/templates/sample.tmpl @@ -0,0 +1 @@ +{{data}}