Skip to content

[2.x] Application.initialize error message refers to the wrong extension/initializer name #4293

@clarkwinkelmann

Description

@clarkwinkelmann

Current Behavior

I get error message "flarum-approval failed to initialize, check the browser console for further information." when the error is actually thrown in the initializer of one of my third-party extensions.

The problem is in the 2.x implementation of Application.initialize. The name of the current initializer/extension is stored in this.currentInitializerExtension, and then accessed from a callback. This results in every callback call to read the value of the last booted initializer, and not the one(s) that experienced errors.

this.currentInitializerExtension = initializer.itemName.includes('/')
? initializer.itemName.replace(/(\/flarum-ext-)|(\/flarum-)/g, '-')
: initializer.itemName;
try {
initializer(this);
} catch (e) {
caughtInitializationErrors.push(() =>
fireApplicationError(
extractText(
app.translator.trans('core.lib.error.extension_initialiation_failed_message', { extension: this.currentInitializerExtension })
),
`${this.currentInitializerExtension} failed to initialize`,
e
)
);
}
});
return caughtInitializationErrors;

This problem did not exist in 1.x because the initializer name was stored in a variable that stayed in scope.

Steps to Reproduce

.

Expected Behavior

.

Screenshots

No response

Environment

  • Flarum version: 2.0.0-beta.4
  • Webserver: apache
  • Hosting environment: local
  • PHP version: 8.3.26
  • Browser: Firefox

Output of php flarum info

Flarum core: 2.0.0-beta.4
PHP version: 8.3.26
MySQL version: 8.0.44-0ubuntu0.24.04.1
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, imagick, exif, mysqli, pdo_mysql, Phar, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, Zend OPcache
+-------------------------------+---------------+------------------------------------------+
| Flarum Extensions             |               |                                          |
+-------------------------------+---------------+------------------------------------------+
| ID                            | Version       | Commit                                   |
+-------------------------------+---------------+------------------------------------------+
| flarum-flags                  | v2.0.0-beta.4 |                                          |
| flarum-approval               | v2.0.0-beta.4 |                                          |
| migratetoflarum-fake-data     | dev-master    | 45a06cb693e0413fbf7c748bc0b32c6411be9a49 |
| flarum-suspend                | v2.0.0-beta.4 |                                          |
| flarum-subscriptions          | v2.0.0-beta.4 |                                          |
| flarum-sticky                 | v2.0.0-beta.4 |                                          |
| flarum-statistics             | v2.0.0-beta.4 |                                          |
| flarum-mentions               | v2.0.0-beta.4 |                                          |
| flarum-markdown               | v2.0.0-beta.4 |                                          |
| flarum-lock                   | v2.0.0-beta.4 |                                          |
| flarum-likes                  | v2.0.0-beta.4 |                                          |
| flarum-lang-english           | v2.0.0-beta.4 |                                          |
| flarum-emoji                  | v2.0.0-beta.4 |                                          |
| flarum-bbcode                 | v2.0.0-beta.4 |                                          |
| clarkwinkelmann-author-change | dev-master    | c26f59af9596459076d29f219bbf20f37ea0502d |
+-------------------------------+---------------+------------------------------------------+
Base URL: http://2.0.flarum.localhost
Installation path: /home/clark/Projects/flarum-2.0
Queue driver: sync
Session driver: file
Mail driver: smtp
Debug mode: ON

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions