OpenMediaVault-Plugin-Developers / openmediavault-backup

Plugin to backup OpenMediaVault for emergency recovery
GNU General Public License v3.0
23 stars 15 forks source link

OMV 3.0.94 + Backup Plugin 3.8 = Javascript error #12

Closed immanuelfodor closed 6 years ago

immanuelfodor commented 6 years ago

Hi Everyone,

Chrome on Win10 gives me an error:

Uncaught TypeError: Cannot read property 'registerNode' of undefined
    at Backup.js:19

The problem is here:

OMV.WorkspaceManager.registerNode({
    id      : 'backup',
    path    : '/system',
    text    : _('Backup'),
    icon16  : 'images/backup.png',
    iconSvg : 'images/backup.svg'
});

Which is caused by I think that the plugin's JS files are included before the workspace manager is available. Here is the JS order in my admin's HTML:

...
<script type="application/javascript" src="/extjs6/ext-all.js"></script>
<script type="application/javascript" src="/extjs6/classic/theme-gray/theme-gray.js"></script>
<script type="application/javascript" src="js/omv/util/i18n.js"></script>
<script type="application/javascript" src="js/omv/util/i18nDict.js"></script>
<script type="application/javascript" src="js/ext-overrides.js"></script>
<script type="application/javascript" src="js/js-overrides.js"></script>
<script type="application/javascript" src="js/omv/globals.js"></script>
<script type="application/javascript" src="js/omv/module/admin/system/backup/SystemBackup.js"></script>
<script type="application/javascript" src="js/omv/module/admin/system/backup/Backup.js"></script>
<script type="application/javascript" src="js/omv/workspace/node/Node.js"></script>
<script type="application/javascript" src="js/omv/WorkspaceManager.js"></script>
<script type="application/javascript" src="js/omv/module/admin/system/System.js"></script>
<script type="application/javascript" src="js/omv/module/admin/system/update/Update.js"></script>
<script type="application/javascript" src="js/omv/form/field/plugin/FieldInfo.js"></script>
<script type="application/javascript" src="js/omv/form/plugin/LinkedFields.js"></script>
<script type="application/javascript" src="js/omv/form/CompositeField.js"></script>
<script type="application/javascript" src="js/omv/form/Panel.js"></script>
<script type="application/javascript" src="js/omv/util/Format.js"></script>
<script type="application/javascript" src="js/omv/window/MessageBox.js"></script>
<script type="application/javascript" src="js/omv/Rpc.js"></script>
<script type="application/javascript" src="js/omv/workspace/form/Panel.js"></script>
<script type="application/javascript" src="js/omv/module/admin/system/update/Settings.js"></script>
<script type="application/javascript" src="js/omv/window/Window.js"></script>
<script type="application/javascript" src="js/omv/window/Upload.js"></script>
<script type="application/javascript" src="js/omv/window/Execute.js"></script>
<script type="application/javascript" src="js/omv/data/reader/RpcJson.js"></script>
<script type="application/javascript" src="js/omv/data/proxy/Rpc.js"></script>
<script type="application/javascript" src="js/omv/data/field/Object.js"></script>
<script type="application/javascript" src="js/omv/data/field/Array.js"></script>
...

This is why the menu item does not show up on the sidebar.

Could you please provide a fix for this? :)

Cheers, Immi

ryecoaaron commented 6 years ago

This sounds like a browser cache issue and/or ad block issue and/or proxy issue. Did you try an incognito window?

immanuelfodor commented 6 years ago

Yes, the same in incognito. However, I forgot to post that there is another error before this Backup.js error, the ext-all.js throws one, so here is the full trace:

Uncaught Error: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required classes: OMV.workspace.form.Panel, OMV.form.field.plugin.FieldInfo
    at new Ext.Error (ext-all.js:22)
    at Function.raise (ext-all.js:22)
    at Object.Ext.raise (ext-all.js:22)
    at Object.load (ext-all.js:22)
    at Object.require (ext-all.js:22)
    at Object.require (ext-all.js:22)
    at Function.<anonymous> (ext-all.js:22)
    at Function.doProcess (ext-all.js:22)
    at Function.process (ext-all.js:22)
    at new d (ext-all.js:22)
Ext.Error @ ext-all.js:22
raise @ ext-all.js:22
Ext.raise @ ext-all.js:22
load @ ext-all.js:22
require @ ext-all.js:22
(anonymous) @ ext-all.js:22
(anonymous) @ ext-all.js:22
doProcess @ ext-all.js:22
process @ ext-all.js:22
d @ ext-all.js:22
create @ ext-all.js:22
define @ ext-all.js:22
(anonymous) @ SystemBackup.js:26

Backup.js:19 Uncaught TypeError: Cannot read property 'registerNode' of undefined
    at Backup.js:19

When I uninstall the plugin, the error changes to a mime error due to OMV internal cache, which I clear by calling this in the terminal:

source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache

After running this, there is no JS error on the admin panel. When I reinstall the backup plugin, the same errors appear again as above. This is an almost fresh OMV with minimal setup, and I tried rebooting after plugin install, between reinstalls, etc. and nothing helps, the JS files are loaded before the referenced object's JS is loaded.

I've just seen this, maybe it could help? https://stackoverflow.com/questions/5715626/ext-loader-not-enabled-missing-required/5715962#5715962 I don't know how to experiment with this, I don't think I should alter anything else, the plugin should just work fine out of the box :)

ryecoaaron commented 6 years ago

This is working just fine on my 3.0.94 installs. There is nothing I can change in the plugin to fix this. All of the plugins basically use the same code in the RegisterNode sections. There must be something wrong with your install. Did you try the apt clean button in omv-extras?

immanuelfodor commented 6 years ago

Yes, I've just tried it, and it also does not help. I also logged in on my phone and the backup plugin menu is not there either, so I don't think it is a browser issue. (Android Chrome) The way the OMV admin page renders the header scripts is in wrong order, can't it be changed from the plugin's code or somehow tweaked to give the plugin lower precedence when the scripts are loaded?

On Dec 20, 2017 23:03, "Aaron Murray" notifications@github.com wrote:

This is working just fine on my 3.0.94 installs. There is nothing I can change in the plugin to fix this. All of the plugins basically use the same code in the RegisterNode sections. There must be something wrong with your install. Did you try the apt clean button in omv-extras?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpenMediaVault-Plugin-Developers/openmediavault-backup/issues/12#issuecomment-353195772, or mute the thread https://github.com/notifications/unsubscribe-auth/AUMXWyM-CoD6I5-p2shhL7X1w3G7eJS6ks5tCYRJgaJpZM4RI2FK .

immanuelfodor commented 6 years ago

I tried adding this line to the beginning of SystemBackup.js but does not help:

Ext.Loader.setConfig({enabled:true});

Removed it, then I tried renaming the module's folder (backup) to something else later in the alphabet (system-backup), then resetting OMV internal cache and browser cache, but also no success. The JS files are loaded in the beginning, although, the folder name successfully changes to system-backup, the same errors are present. Is there something else that can influence the loading order of plugins, a config setting, env variable, anything?

immanuelfodor commented 6 years ago

Oh, man, I think I solved it! :)

Here I've found the same extJS error: https://forum.openmediavault.org/index.php/Thread/11592-LUKS-disk-encryption-plugin/?postID=95969#post95969

Following this thread, there is a comment about requirements loading before the plugin non-deterministically: https://forum.openmediavault.org/index.php/Thread/11592-LUKS-disk-encryption-plugin/?postID=96009#post96009

Now, I looked into the requirements, experimented with adding some to the backup.js but no success. Then I read further the thread and there was a suggestion of adding another dependency, and it solved the issue for the guy: https://forum.openmediavault.org/index.php/Thread/11592-LUKS-disk-encryption-plugin/?postID=96684#post96684

Well, as I was looking the requirements, I looked the other installed plugins' JS files as well, and all used double quotes "..." instead of single quotes '...' in the require statements.

I changed all the quotes in the require lines in both Backup.js and SystemBackup.js in /var/www/openmediavault/js/omv/module/admin/system/backup folder, deleted OMV internal cache with the commands above, cleared browser cache, then it works! The Backup menu is displayed on the sidebar, the menu works as intended, no errors on the console. I think you should publish a new version of the plugin for others, I think I'll not be the only one from now on to have this problem if the extJS included needs double quotes in dependency declarations.

Thanks for the help and creating this plugin, also your quick replies! :)

ryecoaaron commented 6 years ago

While I don't have a problem converting them back to double quotes, Javascript should not care if it is a single quote or double quote. Single quotes are also used in the let's encrypt and borgbackup plugins and no one is having this issue. I think the reason why it fixed it for you is because it updated the cache client and server side. I would be curious to see if it works if you change it back to single quotes.

immanuelfodor commented 6 years ago

Okay, let's see as you suggested:

  1. Replaced back all the double quotes to single quotes in both Backup.js and SystemBackup.js
  2. Ran the server-side cache deletion with source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache
  3. Deleted browser cache and reloaded the admin
  4. => The same errors show up!
  5. Replaced back all the single quotes to double quotes in both Backup.js and SystemBackup.js
  6. Ran the server-side cache deletion with source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache
  7. Deleted browser cache and reloaded the admin
  8. => The errors are gone, everything works fine!

It's indeed the quotes that are causing the errors for me, ExtJS is not interpreting the requires with single quotes.

ryecoaaron commented 6 years ago

I will fix this but I still think this should not be causing a problem. To say ExtJS is not interpreting single quotes is wrong. It isn't on your system but on my 10+ systems, it works fine.