Orion98MC / node_rrd

A node.js native binding for RRDtool (node rrd)
97 stars 25 forks source link

Error when running info() then create() #9

Closed Funi1234 closed 5 years ago

Funi1234 commented 9 years ago

When info() is called and the file doesnt exist it returns "{}". I'm trying to use this to indicate if the rrd file in questions exists.

If the file doesnt exist I then want to call the create() function to create it however an error is returned "opening 'someFile.rrd': No such file or directory".

The create() function alone works correctly and I've only encountered this when the call preceeding the create() is the info() call.

I thought maybe info() is locking the file or something similar but I'm unsure.

rrd.info("someFile.rrd", function (info) {
    if (result === null) { //Check that confirms no rrd exists
        rrd.create("someFile.rrd",30,...,function(error){
                //Error thrown in here
        }) 
    }   
});
Orion98MC commented 9 years ago

Hi,

The error message must come from rrd_info() as it cannot open a missing file and then since there was no error cleanup prior to calling the callback function, it carries on the error in create(). Does the create() create something in this case? However I will add an error cleanup to fix this soon. Thanks for the feedback.

Thierry

tchapi commented 9 years ago

I ran into the same problem. A good alternative is to do :


var fs = require('fs')
filename = "/some/path/to/rrdfile.rrd";

if (!fs.existSync(filename)) {
    // Create your database here
    rrd.create(...);
} else {
    console.log("Database exists ...");
    // You can call rrd.info() here
}
Orion98MC commented 9 years ago

Yes, that's the spirit. Thanks for sharing :)