From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaAIH-0002sV-86 for qemu-devel@nongnu.org; Thu, 10 Sep 2015 18:26:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaAIE-00052j-25 for qemu-devel@nongnu.org; Thu, 10 Sep 2015 18:26:13 -0400 Received: from resqmta-po-01v.sys.comcast.net ([96.114.154.160]:55674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaAID-00051S-Uk for qemu-devel@nongnu.org; Thu, 10 Sep 2015 18:26:10 -0400 From: Eric Blake Date: Thu, 10 Sep 2015 16:25:47 -0600 Message-Id: <1441923949-3370-2-git-send-email-eblake@redhat.com> In-Reply-To: <1441923949-3370-1-git-send-email-eblake@redhat.com> References: <1441923949-3370-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH RFC 1/3] qapi: Improve 'include' error message List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth Use of '"...%s" % include' to print non-strings can lead to ugly messages, such as this (if the .json change is applied without the qapi.py change): Expected a file name (string), got: OrderedDict() Better is to just omit the actual non-string value in the message. Signed-off-by: Eric Blake --- scripts/qapi.py | 4 ++-- tests/qapi-schema/include-non-file.err | 2 +- tests/qapi-schema/include-non-file.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index a38862d..df06421 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -138,8 +138,8 @@ class QAPISchemaParser(object): "Invalid 'include' directive") include = expr["include"] if not isinstance(include, str): - raise QAPIExprError(expr_info, 'Expected a file name ' - '(string), got: %s' % include) + raise QAPIExprError(expr_info, + "Expected a string for 'include'") incl_abs_fname = os.path.join(os.path.dirname(abs_fname), include) # catch inclusion cycle diff --git a/tests/qapi-schema/include-non-file.err b/tests/qapi-schema/include-non-file.err index 9658c78..079120b 100644 --- a/tests/qapi-schema/include-non-file.err +++ b/tests/qapi-schema/include-non-file.err @@ -1 +1 @@ -tests/qapi-schema/include-non-file.json:1: Expected a file name (string), got: ['foo', 'bar'] +tests/qapi-schema/include-non-file.json:1: Expected a string for 'include' diff --git a/tests/qapi-schema/include-non-file.json b/tests/qapi-schema/include-non-file.json index cd43c3f..4711aa4 100644 --- a/tests/qapi-schema/include-non-file.json +++ b/tests/qapi-schema/include-non-file.json @@ -1 +1 @@ -{ 'include': [ 'foo', 'bar' ] } +{ 'include': {} } -- 2.4.3