Skip to content
Snippets Groups Projects
Commit 41e1bfb8 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Resilience around tickit.ini and freqit.ini file open operations.

Throw exceptions rather than just loggin an "Unable to open" error
(easier tracking fo the soruce of the error). Log the description and
errno value associated with the file open failure.

Create the .ini files if they don't already exist (rather than crashing
out with an error).

Replace the deprecated 'e' file open mode flag with 'x'.
parent ace559d2
Branches
Tags
No related merge requests found
......@@ -65,8 +65,8 @@ function TickITCfg() {
}
}
if (!tcfg.open("r"))
throw new Error("Unable to open '"+tcfg.name+"'");
if (!tcfg.open(tcfg.exists ? "r" : "w+"))
throw new Error(tcfg.error + " (" + strerror(tcfg.error) + ") opening '" + tcfg.name + "'");
this.gcfg = tcfg.iniGetObject();
lcprops(this.gcfg);
if (this.gcfg.handler !== undefined) {
......@@ -147,9 +147,8 @@ TickITCfg.prototype.get_next_tic_filename = function()
val = f.readBin();
}
else {
if (!f.open("web+")) {
log(LOG_ERROR, "Unable to open file "+f.name+"!");
return undefined;
if (!f.open("wxb+")) {
throw new Error(f.error + " (" + strerror(f.error) + ") opening '" + f.name + "'");
}
val = -1;
}
......@@ -233,7 +232,7 @@ TickITCfg.prototype.save = function()
}
if (!tcfg.open(tcfg.exists ? 'r+':'w+'))
return "Unable to open '"+tcfg.name+"'";
throw new Error(tcfg.error + " (" + strerror(tcfg.error) + ") opening '" + tcfg.name + "'");
writesect(null, this.gcfg);
sects = tcfg.iniGetSections().map(function(v){return v.toLowerCase();});
......@@ -269,9 +268,8 @@ function FREQITCfg()
var key;
var sects;
if (!f.open('r')) {
log(LOG_ERROR, "Unable to open '"+f.name+"'");
return;
if (!f.open(f.exists ? 'r' : 'w+')) {
throw new Error(f.error + " (" + strerror(f.error) + ") opening '" + f.name + "'");
}
// TODO: Support requiring passwords for specific files/dirs
this.dirs = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment