1

I am getting the error "id.replace is not a function"

Below is what I believe the relevant code is. I am missing something obvious, but my brain is currently mush.

getSyncDbFile: function (config, id) {
    if (id === null)
    {
        com.synckolab.tools.logMessage("Error: entry has no id (" +config.name + ": " + config.type + ")", com.synckolab.global.LOG_ERROR);
        return null;
    }

    com.synckolab.tools.logMessage("syncDbFile:  (" +com.synckolab.tools.text.fixNameToMiniCharset(config.serverKey) + "/" + config.type + "_" + config.name + "/" + id + ")", com.synckolab.global.LOG_ERROR);

    id = id.replace(/[ :.;$\\\/]\#\@/g, "_");
    var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
    try {
        file.append("synckolab");
        if (!file.exists()) {
            file.create(1, parseInt("0775", 8));
        }

        file.append(com.synckolab.tools.text.fixNameToMiniCharset(config.serverKey));
        if (!file.exists()) {
            file.create(1, parseInt("0775", 8));
        }


        file.append(config.type + "_" + config.name);
        if (!file.exists()) {
            file.create(1, parseInt("0775", 8));
        }

        file.append(id);
    }
    catch (ex)
    {
        com.synckolab.tools.logMessage("Problem with getting syncDbFile:  (" +com.synckolab.tools.text.fixNameToMiniCharset(config.serverKey) + "/" + config.name + ": " + config.type + ": " + id + ")\n" + ex, com.synckolab.global.LOG_ERROR);
        return null;
    }
    return file;
}
user1514992
  • 33
  • 3
  • 7

3 Answers3

2

As others have pointed out, id needs to be a string. We have no hint as to what type it is.

Just before the line

id = id.replace(/[ :.;$\\\/]\#\@/g, "_");

Add these two lines:

console.log(id);
console.log(typeof id);

That will let us know what those are and if the right values are being passed.

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • I am troublshooting another error and working my way backwards to try and get to the root of the problem This is somewhere around step 16 in unfamiliar territory. It is a thunderbird plugin that is syncing contacts & calendars with an imap server. This specific problem is in tools.js and the source can be found [here](http://www.mozdev.org/source/browse/synckolab/src/chrome/content/synckolab/) and the devs site is [here](http://www.gargan.org/en/Mozilla_Extensions/SyncKolab/CVS_Nightly/). `console.log(id); console.log(typeof id);` doesn't show anything in the thunderbird error console – user1514992 Sep 18 '12 at 17:23
  • OK - in thunderbird, you have to do `Application.console.log` and doing that gave me "True" and "Boolean" – user1514992 Sep 18 '12 at 17:41
  • If 'id' is a Boolean, then you have got a problem outside of the this code sample that goes to whatever calls `getSyncDbFile`. – Jeremy J Starcher Sep 18 '12 at 17:51
1

Have You tried it??

id = String(id).replace(/[ :.;$\\\/]\#\@/g, "_"); 

I think this will work. Since replace is a String Function.

Note: by using this method, it will give a boolean results rather than return a string.

Regexident
  • 29,441
  • 10
  • 93
  • 100
Nowshath
  • 832
  • 7
  • 14
0

Change :

id.replace(/[ :.;$\\\/]\#\@/g, "_");

to:

(id+"").replace(/[ :.;$\\\/]\#\@/g, "_");
driangle
  • 11,601
  • 5
  • 47
  • 54