Commit ab188117 by Edgar HIPP

No more try catch around getValue

parent 1ae98fee
### unreleased (master branch) ### unreleased (master branch)
- Breaking : The image module no longer swallows error thrown by `options.getImage` and `options.getSize`. It is the implementors responsibility to not throw any errors, or the error will be passed. You can return a falsy value in getImage to not render an image at all.
### 3.0.2 ### 3.0.2
- Fix issue with PPTX : Before, you had to add to your options : {fileType: "pptx"} in the module options passed as argument in the constructor of the module. Now, the fileType is retrieved from the main docxtemplater. - Fix issue with PPTX : Before, you had to add to your options : {fileType: "pptx"} in the module options passed as argument in the constructor of the module. Now, the fileType is retrieved from the main docxtemplater.
......
...@@ -91,20 +91,18 @@ class ImageModule { ...@@ -91,20 +91,18 @@ class ImageModule {
if (!part.type === "placeholder" || part.module !== moduleName) { if (!part.type === "placeholder" || part.module !== moduleName) {
return null; return null;
} }
try {
const tagValue = options.scopeManager.getValue(part.value); const tagValue = options.scopeManager.getValue(part.value);
if (!tagValue) { if (!tagValue) {
throw new Error("tagValue is empty"); return {value: this.fileTypeConfig.tagTextXml};
} }
const imgBuffer = this.options.getImage(tagValue, part.value); const imgBuffer = this.options.getImage(tagValue, part.value);
if (!imgBuffer) {
return {value: this.fileTypeConfig.tagTextXml};
}
const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer); const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
const sizePixel = this.options.getSize(imgBuffer, tagValue, part.value); const sizePixel = this.options.getSize(imgBuffer, tagValue, part.value);
return this.getRenderedPart(part, rId, sizePixel); return this.getRenderedPart(part, rId, sizePixel);
} }
catch (e) {
return {value: this.fileTypeConfig.tagTextXml};
}
}
getRenderedPart(part, rId, sizePixel) { getRenderedPart(part, rId, sizePixel) {
if (isNaN(rId)) { if (isNaN(rId)) {
throw new Error("rId is NaN, aborting"); throw new Error("rId is NaN, aborting");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment