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

Pass command code to errorHandler during processCmd #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidjb
Copy link
Contributor

@davidjb davidjb commented May 2, 2024

In an invalid structured FOR command in a document, such as:

+++FOR person+++

this raises an exception from processForIf which gets caught by the catch after this try block:

    if (ctx.options.errorHandler != null) {
      return ctx.options.errorHandler(err);
    }

Currently, only the err is passed through to the errorHandler, whereas all other calls to the errorHandler are supplied with a second argument, the command code (ref: https://github.com/guigrpa/docx-templates/#custom-error-handler).

This PR adjusts the processCmd flow slightly to ensure that the command code is available in the catch block. The moved splitCommand does not throw exceptions so this is safe to be moved up in order to make cmdRest available to the catch.

Tests have been added for the invalid FOR structure above, both with and without an errorHandler which didn't appear to be tested previously.

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

Successfully merging this pull request may close these issues.

1 participant