gagle / node-properties

.properties parser/stringifier.
MIT License
133 stars 42 forks source link

no method 'charCodeAt' error when parsing property file #7

Closed phtrivier closed 10 years ago

phtrivier commented 10 years ago

I'm trying to read the content of a properties file :

var path = "./foo.properties";
var options = {
    path : true,
    namespaces : true
};
properties.parse(path, options, function (err, obj) {
    console.log("Configuration read", obj);
});

foo.properties contains this :

foo = 1

I get the following error :

/home/phtrivier/prj/platform/git/av-ui/av-server/node_modules/properties/lib/parse.js:122
        code = data.charCodeAt (i);
                    ^
TypeError: Object foo = 1 has no method 'charCodeAt'
    at module.exports (/home/phtrivier/prj/platform/git/av-ui/av-server/node_modules/properties/lib/parse.js:122:15)
    at build (/home/phtrivier/prj/platform/git/av-ui/av-server/node_modules/properties/lib/read.js:347:2)
    at module.exports (/home/phtrivier/prj/platform/git/av-ui/av-server/node_modules/properties/lib/read.js:427:5)
    at fs.readFile (fs.js:176:14)
    at Object.oncomplete (fs.js:297:15)

So it seems like the file is propertly located and parsed, but for some reason the properties can not be read...

Am i missing something obvious ?

gagle commented 10 years ago

I don't receive any error, it returns to me:

Configuration read { foo: 1 }

Are you using the last version? Try removing the module and installing it again.

Do you have any fs wrapper of any kind? The error is produced just before the parser starts reading the data.

phtrivier commented 10 years ago

I'm running it as part of a grunt task... could that change things ?

gagle commented 10 years ago

mmm... I'm not sure, I don't use grunt. What tasks are you using?

phtrivier commented 10 years ago

I'm defining a custom task to create the folder ... maybe it's because I'm inside of grunt that the package doesn't work. Apparently there are grunt specific tasks do deal with folder creation / removal, I'll try and use those instead...

Thanks.


En date de : Mer 11.12.13, Gabriel Llamas notifications@github.com a écrit :

Objet: Re: [node-properties] no method 'charCodeAt' error when parsing property file (#7) À: "gagle/node-properties" node-properties@noreply.github.com Cc: "Pierre-Henri Trivier" phtrivier@yahoo.fr Date: Mercredi 11 décembre 2013, 14h27

mmm... I don't know, I don't use grunt. What tasks are you using?

— Reply to this email directly or view it on GitHub.

phtrivier commented 10 years ago

Ok, my bad, I'm not using it in grunt at all, it's in an expressjs app (I got confused with another issue...) - although the app is run by grunt, if that can change something...

And I'm using :

phtrivier commented 10 years ago

This line is supiscious in read.js (line 427)

            fs.readFile (data, { encoding: "utf8" }, function (error, data){
                if (error) return cb (error);
                build (data, options, ".", cb);
            });

In my case, fs.readFile is called with 'data' being the path to my file ; then, once read, the callback is called with data being an object printed like <Buffer 66 6f 6f 20 3d 20 74 72 75 65> . This is what is in turn passed to build, then parse, etc... And it does not seem to have a chartCodeAt method. Do you expect data to be a String ?

gagle commented 10 years ago

This module only works with node 0.10 and greater. I think that the error is produced because in 0.8.x, readFile expects a string as the second parameter (the encoding). Can you try to modify the line 425 from read.js to this one?

Before:

fs.readFile (data, { encoding: "utf8" }, function (error, data){

After:

fs.readFile (data, "utf8", function (error, data){
phtrivier commented 10 years ago

Right, it's because of the api break, using the old signature works.

I'll try upgrading nodejs.

Might be helpfull mentioning the required nodejs version in the doc...

Thanks !


En date de : Mer 11.12.13, Gabriel Llamas notifications@github.com a écrit :

Objet: Re: [node-properties] no method 'charCodeAt' error when parsing property file (#7) À: "gagle/node-properties" node-properties@noreply.github.com Cc: "Pierre-Henri Trivier" phtrivier@yahoo.fr Date: Mercredi 11 décembre 2013, 17h41

This module only works with node 0.10 and greater. I think that the error is produced because in 0.8.x, readFile expects a string as the second parameter (the encoding). Can you try to modify the line 425 from read.js to this one?

Before:

fs.readFile (data, { encoding: "utf8" }, function (error, data){

After:

fs.readFile (data, "utf8", function (error, data){

— Reply to this email directly or view it on GitHub.

gagle commented 10 years ago

Perfect! You can find the required version in the package.json file.