Macro fails with weird exc

Having a macro here:

var log = ko.logging.getLogger("macro");
try {
    var doc = ko.views.manager.currentView.koDoc;
    if (doc.file.scheme != "file") {
        return;
    }
    var file = Components.classes["@mozilla.org/file/local;1"]
                         .createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath(doc.file.path);
    var backupFile = Components.classes["@mozilla.org/file/local;1"]
                         .createInstance(Components.interfaces.nsILocalFile);

    var fileName = doc.file.displayPath;
    fileName = fileName.replace(/(\\|\:)/g,'-');
    var date     = new Date();

    var Year     = date.getFullYear();
    var Month    = date.getMonth();
    var Day      = date.getDate();
    var Hour     = date.getHours();
    var Minute   = date.getMinutes();
    var Second   = date.getSeconds();

    if(Month<10) Month   = "0" + Month;
    if(Day<10) Day       = "0" + Day;
    if(Hour<10) Hour     = "0" + Hour;
    if(Minute<10) Minute = "0" + Minute;
    if(Second<10) Second = "0" + Second;

    var timestamp = Year+"-"+Month+"-"+Day+"_"+Hour+"-"+Minute+"-"+Second;

    backupFile.initWithPath("/tmp/.komodo_backup/" + fileName + "." + timestamp + ".bak");

    file.copyTo(backupFile.parent, backupFile.leafName);
}
catch(e) {
    alert(e);
    log.exception(e, "Failed macro: ");
}

return false;

That worked fine with 9.1.0, burps with 9.2.1 with the alert

file_changed--macro2://11167/backup_all.js
TypeError: views[0].document is undefined

No signs of a log entry :-(, what the heck could it be?

that macro is triggered “Before file save”

I’ve changed it a bit just to fix the error you get. I highly recommend you to use Komodo SDK API, not Legacy API (such as Components.classes, etc.)

var log = require("ko/logging").getLogger("macro");
try {
    var view = require("ko/views").current();
    if (!view.file || view.file.scheme != "file") {
        return;
    }
    var file = Components.classes["@mozilla.org/file/local;1"]
                         .createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath(view.file.path);
    var backupFile = Components.classes["@mozilla.org/file/local;1"]
                         .createInstance(Components.interfaces.nsILocalFile);

    var fileName = view.file.displayPath;
    fileName = fileName.replace(/(\\|\:)/g,'-');
    var date     = new Date();

    var Year     = date.getFullYear();
    var Month    = date.getMonth();
    var Day      = date.getDate();
    var Hour     = date.getHours();
    var Minute   = date.getMinutes();
    var Second   = date.getSeconds();

    if(Month<10) Month   = "0" + Month;
    if(Day<10) Day       = "0" + Day;
    if(Hour<10) Hour     = "0" + Hour;
    if(Minute<10) Minute = "0" + Minute;
    if(Second<10) Second = "0" + Second;

    var timestamp = Year+"-"+Month+"-"+Day+"_"+Hour+"-"+Minute+"-"+Second;

    backupFile.initWithPath("/tmp/.komodo_backup/" + fileName + "." + timestamp + ".bak");

    file.copyTo(backupFile.parent, backupFile.leafName);
}
catch(e) {
    alert(e);
    log.exception(e, "Failed macro: ");
}

return false;

To the point; your macro assumes that koDoc is defined. This will not be the case if the current view is not an editor buffer and so you will get an error like that.

You need a check like:

    if (! doc || doc.file.scheme != "file") {
        return;
    }

thanks, turns out that actual culprit was the addon morekomodo 1.8.3 which is disabled in 9.1.0 but somehow got enabled again in 9.2.1, because add-on compatibility checking got disabled

Thanks for letting us know. We will need to communicate this in our future releases that disabled add-ons may be re-enabled after upgrading Komodo due to our new package management capabilities (as mentioned in the ticket you opened).