All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v6 07/17] qapi: use a QAPIParseError in parser
Date: Thu, 22 Dec 2016 11:16:28 +0100	[thread overview]
Message-ID: <87wpes46bn.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20161206141343.28044-8-marcandre.lureau@redhat.com> ("Marc-André Lureau"'s message of "Tue, 6 Dec 2016 17:13:33 +0300")

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi.py                          | 13 +++++++------
>  tests/qapi-schema/include-cycle.err      |  2 +-
>  tests/qapi-schema/include-format-err.err |  2 +-
>  tests/qapi-schema/include-no-file.err    |  2 +-
>  tests/qapi-schema/include-non-file.err   |  2 +-
>  tests/qapi-schema/include-self-cycle.err |  2 +-
>  6 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 5885c9e4ad..5423b64b23 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -148,19 +148,19 @@ class QAPISchemaParser(object):
>              expr = self.get_expr(False)
>              if isinstance(expr, dict) and "include" in expr:
>                  if len(expr) != 1:
> -                    raise QAPISemError(info, "Invalid 'include' directive")
> +                    raise QAPIParseError(self, "Invalid 'include' directive")
>                  include = expr["include"]
>                  if not isinstance(include, str):
> -                    raise QAPISemError(info,
> -                                       "Value of 'include' must be a string")
> +                    raise QAPIParseError(self,
> +                                         "Value of 'include' must be a string")
>                  incl_abs_fname = os.path.join(os.path.dirname(abs_fname),
>                                                include)
>                  # catch inclusion cycle
>                  inf = info
>                  while inf:
>                      if incl_abs_fname == os.path.abspath(inf['file']):
> -                        raise QAPISemError(info, "Inclusion loop for %s"
> -                                           % include)
> +                        raise QAPIParseError(self, "Inclusion loop for %s"
> +                                             % include)
>                      inf = inf['parent']
>                  # skip multiple include of the same file
>                  if incl_abs_fname in previously_included:
> @@ -168,7 +168,8 @@ class QAPISchemaParser(object):
>                  try:
>                      fobj = open(incl_abs_fname, 'r')
>                  except IOError as e:
> -                    raise QAPISemError(info, '%s: %s' % (e.strerror, include))
> +                    raise QAPIParseError(self, '%s: %s' %
> +                                         (e.strerror, include))
>                  exprs_include = QAPISchemaParser(fobj, previously_included,
>                                                   info)
>                  self.exprs.extend(exprs_include.exprs)
> diff --git a/tests/qapi-schema/include-cycle.err b/tests/qapi-schema/include-cycle.err
> index bdcd07dce2..f96edd2eff 100644
> --- a/tests/qapi-schema/include-cycle.err
> +++ b/tests/qapi-schema/include-cycle.err
> @@ -1,3 +1,3 @@
>  In file included from tests/qapi-schema/include-cycle.json:1:
>  In file included from tests/qapi-schema/include-cycle-b.json:1:
> -tests/qapi-schema/include-cycle-c.json:1: Inclusion loop for include-cycle.json
> +tests/qapi-schema/include-cycle-c.json:1:36: Inclusion loop for include-cycle.json

Location :1:36 points to end of include expression.

> diff --git a/tests/qapi-schema/include-format-err.err b/tests/qapi-schema/include-format-err.err
> index 721ff4eccc..ac79ee4769 100644
> --- a/tests/qapi-schema/include-format-err.err
> +++ b/tests/qapi-schema/include-format-err.err
> @@ -1 +1 @@
> -tests/qapi-schema/include-format-err.json:1: Invalid 'include' directive
> +tests/qapi-schema/include-format-err.json:2:17: Invalid 'include' directive
> diff --git a/tests/qapi-schema/include-no-file.err b/tests/qapi-schema/include-no-file.err

Likewise.

> index d5b9b22d85..de321ac477 100644
> --- a/tests/qapi-schema/include-no-file.err
> +++ b/tests/qapi-schema/include-no-file.err
> @@ -1 +1 @@
> -tests/qapi-schema/include-no-file.json:1: No such file or directory: include-no-file-sub.json
> +tests/qapi-schema/include-no-file.json:1:42: No such file or directory: include-no-file-sub.json
> diff --git a/tests/qapi-schema/include-non-file.err b/tests/qapi-schema/include-non-file.err
> index faae1eacf1..345f6803eb 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: Value of 'include' must be a string
> +tests/qapi-schema/include-non-file.json:1:18: Value of 'include' must be a string

Likewise.

> diff --git a/tests/qapi-schema/include-self-cycle.err b/tests/qapi-schema/include-self-cycle.err
> index 981742ae5f..abfc3ed6f3 100644
> --- a/tests/qapi-schema/include-self-cycle.err
> +++ b/tests/qapi-schema/include-self-cycle.err
> @@ -1 +1 @@
> -tests/qapi-schema/include-self-cycle.json:1: Inclusion loop for include-self-cycle.json
> +tests/qapi-schema/include-self-cycle.json:1:41: Inclusion loop for include-self-cycle.json

Likewise.

The reason for this location is that the error isn't actually a parse
error.

Parse errors happen when the parser runs into a unexpected token, and
then the location stored in the parser points exactly there.  Good.

The errors above happen while checking an expression the parser
accepted, in other words, they're semantic errors.  Because the parser
already accepted the expression, the location stored in it points beyond
the expression.  Using it is not so good.

I proposed to use QAPIParseError here.  Sorry for misleading you.

Thankfully, you made it its own patch, which should be easy to drop.

  reply	other threads:[~2016-12-22 10:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 14:13 [Qemu-devel] [PATCH v6 00/17] qapi doc generation (whole version, squashed) Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 01/17] qapi: improve device_add schema Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 02/17] qapi: improve TransactionAction doc Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 03/17] qga/schema: improve guest-set-vcpus Returns: section Marc-André Lureau
2016-12-21 10:13   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 04/17] qapi: add some sections in docs Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 05/17] docs: add master qapi texi files Marc-André Lureau
2016-12-21 16:49   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 06/17] qapi: rework qapi Exception Marc-André Lureau
2016-12-22 10:03   ` Markus Armbruster
2017-01-05 18:26     ` Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 07/17] qapi: use a QAPIParseError in parser Marc-André Lureau
2016-12-22 10:16   ` Markus Armbruster [this message]
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 08/17] qapi: add qapi2texi script Marc-André Lureau
2016-12-22 19:29   ` Markus Armbruster
2017-01-09 14:09     ` Marc-André Lureau
2017-01-11 12:29       ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 09/17] texi2pod: learn quotation, deftp and deftypefn Marc-André Lureau
2016-12-22 20:02   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 10/17] json: reorder documentation body Marc-André Lureau
2016-12-22 20:48   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 11/17] (SQUASHED) move doc to schema Marc-André Lureau
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 12/17] docs: add qemu logo to pdf Marc-André Lureau
2016-12-22 20:59   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 13/17] build-sys: use --no-split for info Marc-André Lureau
2016-12-22 21:05   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 14/17] build-sys: remove dvi doc generation Marc-André Lureau
2016-12-22 21:09   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 15/17] build-sys: use a generic TEXI2MAN rule Marc-André Lureau
2016-12-22 21:15   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 16/17] build-sys: add txt documentation rules Marc-André Lureau
2016-12-22 21:16   ` Markus Armbruster
2016-12-06 14:13 ` [Qemu-devel] [PATCH v6 17/17] build-sys: add qapi doc generation targets Marc-André Lureau
2016-12-22 21:22   ` Markus Armbruster
2017-01-05 18:19     ` Marc-André Lureau
2016-12-23  9:48 ` [Qemu-devel] [PATCH v6 00/17] qapi doc generation (whole version, squashed) Markus Armbruster
2017-01-09 10:46   ` Marc-André Lureau

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=87wpes46bn.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.