fancytree icon indicating copy to clipboard operation
fancytree copied to clipboard

Initialization error handling

Open crowne opened this issue 1 year ago • 0 comments

I've noticed a bug with error handling during initialization.

This was done with version 2.38.3

Stack trace looks like this from the console:

jquery.fancytree.js:184 Uncaught TypeError: Cannot read properties of undefined (reading 'fancytree')
    at _assert (jquery.fancytree.js:184:1)
    at jquery.fancytree.js:208:1
    at jquery.fancytree.js:26:9
    at jquery.fancytree.js:32:1
    at jquery.fancytree.js:7374:4

The function below is being called with parameter values cond: undefined msg: "Fancytree requires jQuery UI (http://jqueryui.com)"

	function _assert(cond, msg) {
		// TODO: see qunit.js extractStacktrace()
		if (!cond) {
			msg = msg ? ": " + msg : "";
			msg = "Fancytree assertion failed" + msg;

			// consoleApply("assert", [!!cond, msg]);

			// #1041: Raised exceptions may not be visible in the browser
			// console if inside promise chains, so we also print directly:
			$.ui.fancytree.error(msg);

			// Throw exception:
			$.error(msg);
		}
	}

Expected and Actual Behavior

The problem comes in on this line $.ui.fancytree.error(msg); It's trying to report the fact that jQuery UI isn't loaded but then it references $.ui

The call to $.ui.fancytree.error(msg); needs a guard

if ( $.hasOwnProperty('ui') && $.ui.hasOwnProperty('fancytree') ) {
    $.ui.fancytree.error(msg);
}

Environment

  • Chrome Version 128.0.6613.85
  • "jquery": "^2.1.1", "jquery-ui": "^1.12.1",
  • Fancytree version: "jquery.fancytree": "^2.38.3", enabled/affected extensions:

crowne avatar Aug 28 '24 20:08 crowne