Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINK inside FOR throwing 'INTERNAL_ERROR' in v4.1.1 #133

Closed
chelbighofrane opened this issue Jun 8, 2020 · 13 comments
Closed

LINK inside FOR throwing 'INTERNAL_ERROR' in v4.1.1 #133

chelbighofrane opened this issue Jun 8, 2020 · 13 comments
Labels

Comments

@chelbighofrane
Copy link

Unfortunately the error still occurs in version 4.1.1

@jjhbw
Copy link
Collaborator

jjhbw commented Jun 8, 2020

Hmmm, thats weird. Do you have a minimal repro case? Including the template please.

I already tried to reproduce this in #83, and I made a regression test for this. The template that this test uses is https://github.com/guigrpa/docx-templates/blob/master/src/__tests__/fixtures/link-regression-issue-83.docx

@chelbighofrane
Copy link
Author

This is the template: temp.docx
the code:
code.txt
and this is the error I get :
error.txt

jjhbw added a commit that referenced this issue Jun 8, 2020
…ssue likely caused by a corrupted template.
jjhbw added a commit that referenced this issue Jun 8, 2020
…ssue likely caused by a corrupted template.
@jjhbw
Copy link
Collaborator

jjhbw commented Jun 8, 2020

Thanks.

When opening your template (temp.docx), Word 2016 uses Compatibility Mode. This suggests that the file is corrupt or otherwise broken. Which version of Word did you use to build the template? Please ensure you are running the latest version of your MS Word product (with all the latest patches).

I tried to build a reproduction case by copying the text contents of your template into a new Word file, see 02271fe. Weirdly, this test passes without a problem...

Any ideas what the cause might be?

@chelbighofrane
Copy link
Author

I was using 2010 version and also I tried with 2016 and still having the same error. Weird! cause other features(html,images,loop,conditions,link outside loops ...) are working as expected except links in loop. :/

@jjhbw
Copy link
Collaborator

jjhbw commented Jun 15, 2020

I'll close this for now as I'm pretty sure this involves a corrupted template.. I'm sorry I couldn't help you out further. Please let me know if you find out more!

@jjhbw jjhbw closed this as completed Jun 15, 2020
@DvirH
Copy link

DvirH commented Aug 26, 2020

It happens to me as well. Im using most recent office version. I found work around using the +++HTML tag to add <a>

@jjhbw jjhbw reopened this Aug 26, 2020
@jjhbw jjhbw added the bug label Aug 26, 2020
@jjhbw
Copy link
Collaborator

jjhbw commented Aug 26, 2020

@DvirH can you post a reproduction case with a template and some code?
Also please make sure you're running the latest version of the library.

@DvirH
Copy link

DvirH commented Aug 26, 2020

Here it is... I've uploaded it to my repo
https://github.com/DvirH/reproduce_links

I'm using 4.4.0 version (the last on npm)

jjhbw added a commit that referenced this issue Sep 8, 2020
…ssue possibly caused by a corrupted template?
jjhbw added a commit that referenced this issue Sep 8, 2020
…LINK commands that are formatted (e.g. bold). Thanks @DvirH for providing an example.
jjhbw added a commit that referenced this issue Sep 8, 2020
…LINK commands that are formatted (e.g. bold). Thanks @DvirH for providing an example.
@jjhbw
Copy link
Collaborator

jjhbw commented Sep 8, 2020

@DvirH @chelbighofrane Thanks for your examples!

After a bit of experimentation, it seems that the INTERNAL ERROR only happens when the LINK command is formatted somehow (e.g. bold or underlined). See example template in 9b9d84c.

I'll try and get a fix in, but note that the affected code is pretty deep in the lib and fully grasping what goes wrong may take a while.

@jjhbw
Copy link
Collaborator

jjhbw commented Sep 8, 2020

A short term fix/hack would be to remove all formatting from the affected LINK command in your template.

@jjhbw
Copy link
Collaborator

jjhbw commented Sep 8, 2020

@guigrpa can you maybe give me a pointer here? I stared at this code for a while, but I couldn't find what's going wrong here.

The INTERNAL ERROR is thrown here:

if (move === 'SIDE') {
if (nodeOut._parent == null)
throw new InternalError('node parent is null');
nodeOut = nodeOut._parent;

I have confirmed that this error occurs when LINK commands are formatted (e.g. bold/underlined) and placed within a FOR loop (see example template here 9b9d84c)

Would be great if you could point me in the right direction!

@guigrpa
Copy link
Owner

guigrpa commented Sep 10, 2020

Hmm, it looks like the input and output trees have gotten out of sync. When the next move is to the SIDE, the code first moves the output node pointer up the tree one level, so that a child can be created next as a sibling to the previous node. The code throws because nodeOut has no parent, so the question is: where is it pointing to? Maybe it was moved incorrectly in the previous step?

Since you mention that it happens only within a loop, maybe nodeOut was incorrectly updated at the end of an iteration?

I think it would pay to execute it step by step, watching input and output pointers as they move…

jjhbw added a commit that referenced this issue Mar 1, 2021
…LINK commands that are formatted (e.g. bold). Thanks @DvirH for providing an example.
jjhbw added a commit that referenced this issue Mar 1, 2021
…LINK commands that are formatted (e.g. bold). Thanks @DvirH for providing an example.
jjhbw added a commit that referenced this issue Jul 11, 2021
…commands that are formatted (e.g. bold). Thanks @DvirH for providing an example.
@jjhbw
Copy link
Collaborator

jjhbw commented Jul 12, 2021

Fix released in v4.7.0. Should be on NPM shortly. Let me know if you encounter any weirdness!

@jjhbw jjhbw closed this as completed Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants