public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com
Subject: [PATCH 5/7] Add error handling to read_suppressions.
Date: Mon, 17 Aug 2020 10:38:17 +0100	[thread overview]
Message-ID: <20200817093819.172380-6-gprocida@google.com> (raw)
In-Reply-To: <20200817093819.172380-1-gprocida@google.com>

The top-level parsing functions read_suppresions (one file-scoped
overload and two externally-visible overloads) have no error handling.
This change makes each return a success status and adds placeholders
for where error messages might be emitted.

There are no behavioural changes.

	* include/abg-suppression.h (read_suppresions): Change return
	type to bool.
	* src/abg-suppression.cc (read_suppresions): In the static
	worker overload, return parse success status. In the wrapper
	overloads return false if ini config parsing fails.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 include/abg-suppression.h |  4 +--
 src/abg-suppression.cc    | 57 +++++++++++++++++++++++++++++----------
 2 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/include/abg-suppression.h b/include/abg-suppression.h
index 6383b9322..dbb52de35 100644
--- a/include/abg-suppression.h
+++ b/include/abg-suppression.h
@@ -130,11 +130,11 @@ public:
 					 const suppression_base& suppr);
 }; // end class suppression_base
 
-void
+bool
 read_suppressions(std::istream& input,
 		  suppressions_type& suppressions);
 
-void
+bool
 read_suppressions(const string& file_path,
 		  suppressions_type& suppressions);
 
diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index 736c7f51f..fb97a124b 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -372,10 +372,12 @@ read_file_suppression(const ini::config::section& section,
 ///
 /// @param suppressions out parameter.  The vector of suppressions to
 /// append the newly read suppressions to.
-static void
-read_suppressions(const ini::config& config,
-		  suppressions_type& suppressions)
+///
+/// @return whether the parse was successful.
+static bool
+read_suppressions(const ini::config& config, suppressions_type& suppressions)
 {
+  bool success = true;
   for (ini::config::sections_type::const_iterator i =
 	 config.get_sections().begin();
        i != config.get_sections().end();
@@ -383,18 +385,31 @@ read_suppressions(const ini::config& config,
     {
       const ini::config::section_sptr& section = *i;
       const std::string& name = section->get_name();
+      bool section_success;
       suppression_sptr s;
       if (name == "suppress_type")
-	read_type_suppression(*section, s);
+	section_success = read_type_suppression(*section, s);
       else if (name == "suppress_function")
-	read_function_suppression(*section, s);
+	section_success = read_function_suppression(*section, s);
       else if (name == "suppress_variable")
-	read_variable_suppression(*section, s);
+	section_success = read_variable_suppression(*section, s);
       else if (name == "suppress_file")
-	read_file_suppression(*section, s);
-      if (s)
+	section_success = read_file_suppression(*section, s);
+      else
+	{
+	  // TODO: maybe emit unknown section name error
+	  success = false;
+	  continue;
+	}
+      if (section_success)
 	suppressions.push_back(s);
+      else
+	{
+	  // TODO: maybe emit section parse failure message
+	  success = false;
+	}
     }
+  return success;
 }
 
 /// Read suppressions specifications from an input stream.
@@ -403,12 +418,19 @@ read_suppressions(const ini::config& config,
 ///
 /// @param suppressions the vector of suppressions to append the newly
 /// read suppressions to.
-void
+///
+/// @return whether the parse was successful
+bool
 read_suppressions(std::istream& input,
 		  suppressions_type& suppressions)
 {
-    if (ini::config_sptr config = ini::read_config(input))
-    read_suppressions(*config, suppressions);
+  ini::config_sptr config = ini::read_config(input);
+  if (!config)
+    {
+      // TODO: maybe report ini configuration parse failure
+      return false;
+    }
+  return read_suppressions(*config, suppressions);
 }
 
 /// Read suppressions specifications from an input file on disk.
@@ -417,12 +439,19 @@ read_suppressions(std::istream& input,
 ///
 /// @param suppressions the vector of suppressions to append the newly
 /// read suppressions to.
-void
+///
+/// @return whether the parse was successful
+bool
 read_suppressions(const string& file_path,
 		  suppressions_type& suppressions)
 {
-  if (ini::config_sptr config = ini::read_config(file_path))
-    read_suppressions(*config, suppressions);
+  ini::config_sptr config = ini::read_config(file_path);
+  if (!config)
+    {
+      // TODO: maybe report ini configuration file_path parse failure
+      return false;
+    }
+  return read_suppressions(*config, suppressions);
 }
 // </suppression_base stuff>
 
-- 
2.28.0.220.ged08abb693-goog


  parent reply	other threads:[~2020-08-17  9:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17  9:38 [PATCH 0/7] Suppression parsing - preparatory work Giuliano Procida
2020-08-17  9:38 ` [PATCH 1/7] Add missing newlines to end of test files Giuliano Procida
2020-10-01 14:36   ` Dodji Seketeli
2020-08-17  9:38 ` [PATCH 2/7] Fix two wrongs in test suppression regex Giuliano Procida
2020-10-01 14:42   ` Dodji Seketeli
2020-08-17  9:38 ` [PATCH 3/7] Better suppression section parsing delegation Giuliano Procida
2020-10-01 15:56   ` Dodji Seketeli
2020-10-02  7:20     ` Giuliano Procida
2020-08-17  9:38 ` [PATCH 4/7] Add read_*_suppression success/failure plumbing Giuliano Procida
2020-08-17  9:38 ` Giuliano Procida [this message]
2020-08-17  9:38 ` [PATCH 6/7] Default construct suppression types Giuliano Procida
2020-08-17  9:38 ` [PATCH 7/7] Refresh getter/setter comments Giuliano Procida
2020-10-02  7:25 ` [PATCH 0/7] Suppression parsing - preparatory work Dodji Seketeli
2020-10-06 20:19   ` Giuliano Procida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200817093819.172380-6-gprocida@google.com \
    --to=gprocida@google.com \
    --cc=dodji@seketeli.org \
    --cc=kernel-team@android.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).