diff options
| -rw-r--r-- | lib/docx/files.js | 5 | ||||
| -rw-r--r-- | tests/docx/files.tests.js | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js index 0e95197..6380ea4 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -14,7 +14,10 @@ exports.uriToPath = uriToPath; function Files(base) { function read(uri, encoding) { return resolveUri(uri).then(function(path) { - return readFile(path, encoding); + return readFile(path, encoding).caught(function(error) { + var message = "could not open external image: '" + uri + "' (document directory: '" + base + "')\n" + error.message; + return promises.reject(new Error(message)); + }); }); } diff --git a/tests/docx/files.tests.js b/tests/docx/files.tests.js index a00b60b..65cd486 100644 --- a/tests/docx/files.tests.js +++ b/tests/docx/files.tests.js @@ -39,6 +39,13 @@ describe("Files", function() { assert.equal(err.message, "could not find external image 'not-a-real-file.png', path of input document is unknown"); }); }); + + test("error if relative uri cannot be opened", function() { + var files = new Files("/tmp"); + return assertError(files.read("not-a-real-file.png", "base64"), function(err) { + assert.equal(err.message, "could not open external image: 'not-a-real-file.png' (document directory: '/tmp')\nENOENT, open '/tmp/not-a-real-file.png'"); + }); + }); }); function assertError(promise, func) { |
