ref: improve error handling
This commit is contained in:
+8
-12
@@ -746,7 +746,7 @@ const execSyncCommand = (cmd, args = []) => {
|
|||||||
const output = cpr.execSync([cmd, ...args].join(" "), { encoding: "utf8" });
|
const output = cpr.execSync([cmd, ...args].join(" "), { encoding: "utf8" });
|
||||||
return output.trim().replace(/\0/g, "");
|
return output.trim().replace(/\0/g, "");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Execute Sync:", error.message);
|
console.error(`Execute Sync: '${[cmd, ...args].join(" ")}' --> ${error.message}`);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -774,17 +774,13 @@ const execAsyncCommand = (cmd, args = [], callback = null) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
proc.on("close", (code) => {
|
proc.on("close", (code) => {
|
||||||
try {
|
const error = errorOutput.trim().replace(/\0/g, "");
|
||||||
if (typeof callback === "function") {
|
const reply = successOutput.trim().replace(/\0/g, "");
|
||||||
if (code === 0) {
|
if (code !== 0 || error) {
|
||||||
callback(successOutput.trim().replace(/\0/g, ""), null);
|
console.error(`Execute Async: '${[cmd, ...args].join(" ")}' --> ${error} (${code})`);
|
||||||
|
if (typeof callback === "function") callback(null, error);
|
||||||
} else {
|
} else {
|
||||||
callback(null, errorOutput.trim().replace(/\0/g, ""));
|
if (typeof callback === "function") callback(reply, null);
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Execute Async:", error.message);
|
|
||||||
if (typeof callback === "function") callback(null, error.message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return proc;
|
return proc;
|
||||||
@@ -830,7 +826,7 @@ const execScriptCommand = (cmd, args = [], callback = null) => {
|
|||||||
});
|
});
|
||||||
proc.on("close", (code) => {
|
proc.on("close", (code) => {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
console.log(`Script exited with error code ${code}.`);
|
console.error(`Script exited with error code (${code}).`);
|
||||||
if (typeof callback === "function") callback(null, code);
|
if (typeof callback === "function") callback(null, code);
|
||||||
} else {
|
} else {
|
||||||
console.log("Script exited successfully.");
|
console.log("Script exited successfully.");
|
||||||
|
|||||||
+2
-2
@@ -432,7 +432,7 @@ const initDisplay = () => {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
hardware.update();
|
hardware.update();
|
||||||
} else {
|
} else {
|
||||||
console.warn("Failed:", error);
|
console.warn("Command Failed:", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (topic === config.brightness_command_topic) {
|
} else if (topic === config.brightness_command_topic) {
|
||||||
@@ -442,7 +442,7 @@ const initDisplay = () => {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
hardware.update();
|
hardware.update();
|
||||||
} else {
|
} else {
|
||||||
console.warn("Failed:", error);
|
console.warn("Command Failed:", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user