From 43e6c6480cddfb35ad354582dbb0f5ebb6b59645 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 24 Aug 2021 18:08:26 +0200 Subject: [PATCH] baseboard(), getDefaultNetworkInterface() fix catch error --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/network.js | 40 ++++++++++++++++++++-------------------- lib/system.js | 7 ++++++- lib/util.js | 2 +- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f2eec..f38bf93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 5.8.2 | 2021-08-24 | `baseboard()`, `getDefaultNetworkInterface()` fix catch error | | 5.8.1 | 2021-08-24 | `battery()` fix capacity | | 5.8.0 | 2021-08-02 | `disksIO()` added waitTime, waitPercent (linux) | | 5.7.14 | 2021-08-01 | `cpu()` cache calculation fix (linux) | diff --git a/docs/history.html b/docs/history.html index 41e4fb5..f12d5da 100644 --- a/docs/history.html +++ b/docs/history.html @@ -56,6 +56,11 @@ + + 5.8.2 + 2021-08-24 + baseboard(), getDefaultNetworkInterface() fix catch error + 5.8.1 2021-08-24 diff --git a/docs/index.html b/docs/index.html index 2d92b89..f29cc64 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.8.1
+
New Version: 5.8.2
diff --git a/lib/network.js b/lib/network.js index bbf3787..0e785af 100644 --- a/lib/network.js +++ b/lib/network.js @@ -39,29 +39,29 @@ let pathToIp; function getDefaultNetworkInterface() { - let ifaces = os.networkInterfaces(); let ifacename = ''; let ifacenameFirst = ''; - - let scopeid = 9999; - - // fallback - "first" external interface (sorted by scopeid) - for (let dev in ifaces) { - if ({}.hasOwnProperty.call(ifaces, dev)) { - ifaces[dev].forEach(function (details) { - if (details && details.internal === false) { - ifacenameFirst = ifacenameFirst || dev; // fallback if no scopeid - if (details.scopeid && details.scopeid < scopeid) { - ifacename = dev; - scopeid = details.scopeid; - } - } - }); - } - } - ifacename = ifacename || ifacenameFirst || ''; - try { + let ifaces = os.networkInterfaces(); + + let scopeid = 9999; + + // fallback - "first" external interface (sorted by scopeid) + for (let dev in ifaces) { + if ({}.hasOwnProperty.call(ifaces, dev)) { + ifaces[dev].forEach(function (details) { + if (details && details.internal === false) { + ifacenameFirst = ifacenameFirst || dev; // fallback if no scopeid + if (details.scopeid && details.scopeid < scopeid) { + ifacename = dev; + scopeid = details.scopeid; + } + } + }); + } + } + ifacename = ifacename || ifacenameFirst || ''; + if (_windows) { // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml let defaultIp = ''; diff --git a/lib/system.js b/lib/system.js index a298856..a510450 100644 --- a/lib/system.js +++ b/lib/system.js @@ -615,7 +615,12 @@ function baseboard(callback) { result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null; // raspberry - const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n'); + let linesRpi = ''; + try { + linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n'); + } catch (e) { + util.noop(); + } const hardware = util.getValue(linesRpi, 'hardware'); if (hardware.startsWith('BCM')) { const rpi = util.decodePiCpuinfo(linesRpi); diff --git a/lib/util.js b/lib/util.js index ce67f4b..32936f3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -112,7 +112,7 @@ function getValue(lines, property, separator, trimmed) { if (trimmed) { line = line.trim(); } - if (line.startsWith(property) && line.match(property + separator)) { + if (line.startsWith(property)) { const parts = trimmed ? lines[i].trim().split(separator) : lines[i].split(separator); if (parts.length >= 2) { parts.shift();