[plasma/kscreen] console: console: handle failures to open configuration files

Vlad Zahorodnii <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 91d3a63a05051a8c57cb8e08f333eff27e06656d by Vlad Zahorodnii, on behalf of Li Kai.
Committed on 24/07/2026 at 07:42.
Pushed by vladz into branch 'master'.

console: handle failures to open configuration files

QFile::open() is marked nodiscard and its result was ignored when
printing serialized configurations.

Report an error when a configuration file cannot be opened. When
processing multiple configuration files, skip an unreadable file and
continue with the remaining files.

M  +8    -2    console/console.cpp

https://invent.kde.org/plasma/kscreen/-/commit/91d3a63a05051a8c57cb8e08f333eff27e06656d

diff --git a/console/console.cpp b/console/console.cpp
index e3008669..ef1be77f 100644
--- a/console/console.cpp
+++ b/console/console.cpp
@@ -133,7 +133,10 @@ void Console::printSerializations()
 {
     if (KWindowSystem::isPlatformWayland()) {
         QFile file(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/kwinoutputconfig.json"));
-        file.open(QFile::ReadOnly);
+        if (!file.open(QFile::ReadOnly)) {
+            qWarning() << "Failed to open" << file.fileName() << file.errorString();
+            return;
+        }
         qDebug().noquote() << file.readAll();
     } else {
         QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kscreen/");
@@ -147,7 +150,10 @@ void Console::printSerializations()
             QJsonParseError error;
             qDebug() << fileName;
             QFile file(path + QLatin1Char('/') + fileName);
-            file.open(QFile::ReadOnly);
+            if (!file.open(QFile::ReadOnly)) {
+                qWarning() << "Failed to open" << file.fileName() << file.errorString();
+                continue;
+            }
             QJsonDocument parser = QJsonDocument::fromJson(file.readAll(), &error);
             if (error.error != QJsonParseError::NoError) {
                 qDebug() << "    can't parse file:";
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.