Skip to content

Add Locale.warn() and Locale.throw(), add tests for them, and use them in several TeX packages.#1482

Open
dpvc wants to merge 1 commit into
feature/locale_finish_texfrom
feature/locale-throw
Open

Add Locale.warn() and Locale.throw(), add tests for them, and use them in several TeX packages.#1482
dpvc wants to merge 1 commit into
feature/locale_finish_texfrom
feature/locale-throw

Conversation

@dpvc
Copy link
Copy Markdown
Member

@dpvc dpvc commented May 24, 2026

This PR adds the Locale.warn() function and renames Locale.error() as Locale.throw(), and uses these in the TeX packages that I mentioned in the finalize-tex branch. It updates the tests to cover these, and moves some output-trapping functions from the testsuite/src/setupTex.ts file to a new traps.ts file. The reason for this is that setupTeX.ts loads node-main, which does two two things that affect the Locale package: because it is component-based, it means Locale.isComponent gets set, which we don't want (that changes the location where Locale looks for the localization files), second, it alters the mathjax.asyncLoad which ends up causing different error messages. I could have gotten around these issues, but it seemed reasonable to separate out the non-tex-based output trapping functions from setupTex.ts in any case, and that avoids the problem.

The change to package.js is to allow access to the new trap.ts file via #helpers/trap.js. The index.js file is modified to export the traps from the new file rather than setupTex.js. The needed traps are loaded into setupTex.ts rather than being defined there. I also fixed some JSDoc @returns that changed after adding the Locale.setLocale() calls (in an earlier PR).

Some tests in Tex.test.ts are adjusted to accommodate the use of Locale.warn() and the removal of the warn() methods that we discussed in our meeting. The Locale.test.ts file is implified to use the trapOutput and trapAsyncOutput() functions from the new traps.ts file, rather that chaining the console.error and console.warn functions by hand, and a new section to test Locale.warn() is added.

The usage of console and throw new Error in several TeX packages are changes to Locale.warn() and Locale.throw() and their warn() methods removed, and the needed messages are added to the localization files.

…m in several TeX packages. Move test trap functions into separate src file.
@dpvc dpvc requested a review from zorkow May 24, 2026 10:28
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