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

Raise an error when a FOR loop is not properly closed. #180

Closed
gitowiec opened this issue Dec 21, 2020 · 9 comments
Closed

Raise an error when a FOR loop is not properly closed. #180

gitowiec opened this issue Dec 21, 2020 · 9 comments

Comments

@gitowiec
Copy link

I can't fill in attached template. All I get is first 4 lines of the template with filled markers and then the rest is cut.
image

I'm attaching the template and the data I want to put in it.

const data = {
        address: 'Długi Targ 200/12, Gdańsk',
        unitName: 'ACME Solutions',
        date: '18.12.2020',
        city: 'Gdańsk',
        nip: '1234567890',
        regon: '456456456',
        representatives: [
          {
            name: 'Osoba Pierwsza',
            contact: '[email protected]',
          },
        ],
        paymentsFrequency: {
          taxYear: '2020',
          quarterly: true,
          choosing: true,
        },
        vatTaxpayerRegistration: {
          choosing: false,
          registeredTaxpayerExempt: true,
        },
      }

Template

Prawne-oswiadczenie-PDOP-VAT.docx

More, when I remove this part of template:

+++FOR representative IN representatives+++
+++INS $representative.name+++ - +++INS $representative.contact+++
+++END-FOR representatives+++

I get an error that


Error: Error executing command 'taxYear'. ReferenceError: taxYear is not defined
    at new CommandExecutionError (node_modules/docx-templates/lib/errors.js:53:28)
    at Object.<anonymous> (node_modules/docx-templates/lib/jsSandbox.js:104:32)
    at step (node_modules/docx-templates/lib/jsSandbox.js:33:23)
    at Object.next (node_modules/docx-templates/lib/jsSandbox.js:14:53)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/jsSandbox.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/docx-templates/lib/jsSandbox.js:4:12)
    at Object.runUserJsAndGetRaw (node_modules/docx-templates/lib/jsSandbox.js:54:12)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/processTemplate.js:478:50
    at step (node_modules/docx-templates/lib/processTemplate.js:33:23)
    at Object.next (node_modules/docx-templates/lib/processTemplate.js:14:53)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/processTemplate.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/docx-templates/lib/processTemplate.js:4:12)
    at processCmd (node_modules/docx-templates/lib/processTemplate.js:435:54)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/processTemplate.js:401:38
    at step (node_modules/docx-templates/lib/processTemplate.js:33:23)
    at Object.next (node_modules/docx-templates/lib/processTemplate.js:14:53)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/processTemplate.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/docx-templates/lib/processTemplate.js:4:12)
    at processText (node_modules/docx-templates/lib/processTemplate.js:370:66)
    at /home/user/workspace/project/packages/web-server/node_modules/docx-templates/lib/processTemplate.js:325:42
    at step (node_modules/docx-templates/lib/processTemplate.js:33:23)
    at Object.next (node_modules/docx-templates/lib/processTemplate.js:14:53)
    at fulfilled (node_modules/docx-templates/lib/processTemplate.js:5:58)

It just ignores the declaration of ALIASes which is just before the usage of taxYear

+++ALIAS ch1 INS paymentsFrequency.monthly+++
+++ALIAS ch2 INS paymentsFrequency.quarterly+++
+++ALIAS chosenText INS paymentsFrequency.chosenText+++
+++ALIAS taxYear INS paymentsFrequency.taxYear+++
@jjhbw
Copy link
Collaborator

jjhbw commented Dec 21, 2020

You are closing the FOR loop properly. You need to use +++END-FOR representative +++ instead of +++END-FOR representatives +++. The rest of the template gets ignored.

I think this case can use a better error message, as an unclosed FOR loop is never intentional. I'll mark it as a potential enhancement.

@jjhbw jjhbw changed the title FOR command is not parsed, rest of the document in the output is erased Raise an error when a FOR loop is not properly closed. Dec 21, 2020
@gitowiec
Copy link
Author

Ok, thanks for finding my error. Strange, because I mechanically wrote representatives

@gitowiec
Copy link
Author

And what about that ALIASes?

@jjhbw
Copy link
Collaborator

jjhbw commented Dec 22, 2020

The ALIAS commands are below the end of the FOR loop, right? As the FOR-loop wasnt properly closed, the rest of the template was ignored.

@gitowiec
Copy link
Author

You should read with understanding. I wrote "More, when I remove this part of template:". read againg my original post

@jjhbw
Copy link
Collaborator

jjhbw commented Dec 22, 2020

Mind the attitude. Note that I'm helping you for free with something that looks like your job. Unless you're working on something that processes invoices for charity, that means i am helping you make money.

Regarding your issue: see the docs on the ALIAS command. You need to resolve the alias with *.

@jjhbw jjhbw closed this as completed Dec 22, 2020
@jjhbw
Copy link
Collaborator

jjhbw commented Dec 22, 2020

Keeping this issue open as the unclosed FOR-loop warning is a nice potential enhancement.

@jjhbw jjhbw reopened this Dec 22, 2020
@jjhbw
Copy link
Collaborator

jjhbw commented Dec 22, 2020

Again, this is free software. I'm not asking you to help me fix any kind of bug, and you're not obligated to use my work.

In your initial post you referred to Error: Error executing command 'taxYear'. ReferenceError: taxYear is not defined, right? There is no asterisk in your call to +++taxYear+++. Same for +++chosenText+++ next to it. Are you referring to another template? I only have the one you sent in your earlier reply.

@jjhbw
Copy link
Collaborator

jjhbw commented Jul 31, 2023

Closing this issue because a lot of its comments have apparently been deleted. A new issue for this problem has been created by someone else with a more elaborate explanation #322 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants