luci-app-vnstat2: fix configuration page when database is empty (#6746)

The output of the command "vnstat --dbiflist 1" is empty when there are
no interfaces in the database. Add a check to avoid a "result.stdout is
undefined" error in that case.

Ref: https://forum.openwrt.org/t/error-in-luci-vnstat2-configuration-menu/179700
Fixes: 3ac4f567df ("luci-app-vnstat2: use more efficient way to get database interfaces")

Signed-off-by: Jan Hoffmann <jan@3e8.eu>
This commit is contained in:
Jan Hoffmann 2023-12-06 02:24:25 +01:00 committed by GitHub
parent b3d1d056f4
commit c0c37903f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,7 @@ return view.extend({
o.load = function(section_id) { o.load = function(section_id) {
return fs.exec('/usr/bin/vnstat', ['--dbiflist', '1']).then(L.bind(function(result) { return fs.exec('/usr/bin/vnstat', ['--dbiflist', '1']).then(L.bind(function(result) {
var databaseInterfaces = []; var databaseInterfaces = [];
if (result.code == 0) { if (result.code == 0 && result.stdout) {
databaseInterfaces = result.stdout.trim().split('\n'); databaseInterfaces = result.stdout.trim().split('\n');
} }