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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible code between i18next v22.1.0 and i18next-fs-backend v2.1.0, causing saveMissing to report error with the callback function. #1890

Closed
kevintap opened this issue Dec 19, 2022 · 2 comments
Assignees

Comments

@kevintap
Copy link

kevintap commented Dec 19, 2022

馃悰 Bug Report

Incompatible code between i18next v22.1.0 and i18next-fs-backend v2.1.0, causing saveMissing to report error with the callback function.

The following commit introduced a problem with the saveMissing function when using i18next-fs-backend: 40db211

The i18next-fs-backend has a create function defined with arguments:

  (languages, namespace, key, fallbackValue, callback)

The new code introduced in v22.1.0 in the commit referenced above has different expectations for the backend's create function and end up passing the options object in place of the callback to the backend. This causes an error since the expected callback object is not a function.

The above referenced commit expects that the backend's create function contain 6 arguments in order to pass a callback to the backend. If the backend's create function contains fewer than 6 arguments, then it will not pass a callback to the backend and instead pass the opts object for the 5th argument.

          var fc = this.backend.create.bind(this.backend);
          if (fc.length < 6) {
            try {
              var r;
              if (fc.length === 5) {
                r = fc(languages, namespace, key, fallbackValue, opts); // <-- for i18next-fs-backend this ends up being called
              } else {
                r = fc(languages, namespace, key, fallbackValue);
              }
              if (r && typeof r.then === 'function') {
                r.then(function (data) {
                  return clb(null, data);
                })["catch"](clb);
              } else {
                clb(null, r);
              }
            } catch (err) {
              clb(err);
            }
          } else {
            fc(languages, namespace, key, fallbackValue, clb, opts);
          }

To Reproduce

enable saveMissing with the default i18next-fs-backend configured

error - unhandledRejection: TypeError: callback is not a function

Expected behavior

No errors reported when saveMissing is enabled.

Your Environment

  • N/A
@adrai adrai self-assigned this Dec 19, 2022
adrai added a commit to i18next/i18next-fs-backend that referenced this issue Dec 19, 2022
@adrai
Copy link
Member

adrai commented Dec 19, 2022

i18next-fs-backend v2.1.1 should fix it

adrai added a commit to i18next/i18next-http-backend that referenced this issue Dec 19, 2022
@kevintap
Copy link
Author

I think this can be closed now. i18next-fs-backend v2.1.1 resolved this. Thanks for the quick turn around.

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

No branches or pull requests

2 participants