From fdda0e14aa04451f30a0f85ff5bc1b5642987ef2 Mon Sep 17 00:00:00 2001
From: Adriaan de Groot <groot@kde.org>
Date: Mon, 26 Feb 2018 20:07:06 +0100
Subject: [PATCH] [libcalamaresui] Improve explainYamlException

 - overloads for common kinds of label
 - improve error reporting when reading settings and branding files
---
 src/libcalamares/Settings.cpp        |  4 ++--
 src/libcalamares/utils/YamlUtils.cpp | 15 ++++++++++++++-
 src/libcalamares/utils/YamlUtils.h   |  2 ++
 src/libcalamaresui/Branding.cpp      |  4 ++--
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp
index 06178c621..732afa8d8 100644
--- a/src/libcalamares/Settings.cpp
+++ b/src/libcalamares/Settings.cpp
@@ -156,12 +156,12 @@ Settings::Settings( const QString& settingsFilePath,
         }
         catch ( YAML::Exception& e )
         {
-            cWarning() << "YAML parser error " << e.what() << "in" << file.fileName();
+            CalamaresUtils::explainYamlException( e, ba, file.fileName() );
         }
     }
     else
     {
-        cWarning() << "Cannot read " << file.fileName();
+        cWarning() << "Cannot read settings file" << file.fileName();
     }
 
     s_instance = this;
diff --git a/src/libcalamares/utils/YamlUtils.cpp b/src/libcalamares/utils/YamlUtils.cpp
index 3bc9c36d2..474ced2a1 100644
--- a/src/libcalamares/utils/YamlUtils.cpp
+++ b/src/libcalamares/utils/YamlUtils.cpp
@@ -114,6 +114,19 @@ void
 explainYamlException( const YAML::Exception& e, const QByteArray& yamlData, const char *label )
 {
     cWarning() << "YAML error " << e.what() << "in" << label << '.';
+    explainYamlException( e, yamlData );
+}
+
+void
+explainYamlException( const YAML::Exception& e, const QByteArray& yamlData, const QString& label )
+{
+    cWarning() << "YAML error " << e.what() << "in" << label << '.';
+    explainYamlException( e, yamlData );
+}
+
+void
+explainYamlException( const YAML::Exception& e, const QByteArray& yamlData )
+{
     if ( ( e.mark.line >= 0 ) && ( e.mark.column >= 0 ) )
     {
         // Try to show the line where it happened.
@@ -172,7 +185,7 @@ loadYaml(const QString& filename, bool* ok)
         }
         catch ( YAML::Exception& e )
         {
-            explainYamlException( e, ba, filename.toLatin1().constData() );
+            explainYamlException( e, ba, filename );
             return QVariantMap();
         }
     }
diff --git a/src/libcalamares/utils/YamlUtils.h b/src/libcalamares/utils/YamlUtils.h
index ad8de7d57..268c0bdc7 100644
--- a/src/libcalamares/utils/YamlUtils.h
+++ b/src/libcalamares/utils/YamlUtils.h
@@ -57,6 +57,8 @@ QVariant yamlMapToVariant( const YAML::Node& mapNode );
  * Uses @p label when labeling the data source (e.g. "netinstall data")
  */
 void explainYamlException( const YAML::Exception& e, const QByteArray& data, const char *label );
+void explainYamlException( const YAML::Exception& e, const QByteArray& data, const QString& label );
+void explainYamlException( const YAML::Exception& e, const QByteArray& data );
 
 } //ns
 
diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp
index 584d85c0b..c71b1daa5 100644
--- a/src/libcalamaresui/Branding.cpp
+++ b/src/libcalamaresui/Branding.cpp
@@ -179,7 +179,7 @@ Branding::Branding( const QString& brandingFilePath,
         }
         catch ( YAML::Exception& e )
         {
-            cWarning() << "YAML parser error " << e.what() << "in" << file.fileName();
+            CalamaresUtils::explainYamlException( e, ba, file.fileName() );
         }
 
         QDir translationsDir( componentDir.filePath( "lang" ) );
@@ -192,7 +192,7 @@ Branding::Branding( const QString& brandingFilePath,
     }
     else
     {
-        cWarning() << "Cannot read " << file.fileName();
+        cWarning() << "Cannot read branding file" << file.fileName();
     }
 
     s_instance = this;