qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] trace: include filename when printing parser error messages
@ 2018-03-06 15:46 Daniel P. Berrangé
  2018-03-06 18:47 ` Philippe Mathieu-Daudé
  2018-03-08 15:21 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel P. Berrangé @ 2018-03-06 15:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi, Daniel P. Berrangé

Improves error messages from:

  ValueError: Error on line 72: need more than 1 value to unpack

To

  ValueError: Error at /home/berrange/src/virt/qemu/trace-events:72:
    need more than 1 value to unpack

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/simpletrace.py        | 4 ++--
 scripts/tracetool.py          | 2 +-
 scripts/tracetool/__init__.py | 6 ++++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
index a3a6315055..fefc0806b8 100755
--- a/scripts/simpletrace.py
+++ b/scripts/simpletrace.py
@@ -168,7 +168,7 @@ class Analyzer(object):
 def process(events, log, analyzer, read_header=True):
     """Invoke an analyzer on each event in a log."""
     if isinstance(events, str):
-        events = read_events(open(events, 'r'))
+        events = read_events(open(events, 'r'), events)
     if isinstance(log, str):
         log = open(log, 'rb')
 
@@ -233,7 +233,7 @@ def run(analyzer):
                          '<trace-file>\n' % sys.argv[0])
         sys.exit(1)
 
-    events = read_events(open(sys.argv[1], 'r'))
+    events = read_events(open(sys.argv[1], 'r'), sys.argv[1])
     process(events, sys.argv[2], analyzer, read_header=read_header)
 
 if __name__ == '__main__':
diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index c55a21518b..fe2b0771f2 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -142,7 +142,7 @@ def main(args):
     events = []
     for arg in args:
         with open(arg, "r") as fh:
-            events.extend(tracetool.read_events(fh))
+            events.extend(tracetool.read_events(fh, arg))
 
     try:
         tracetool.generate(events, arg_group, arg_format, arg_backends,
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 52cc687ae3..b645be30d1 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -336,13 +336,15 @@ class Event(object):
                      self)
 
 
-def read_events(fobj):
+def read_events(fobj, fname):
     """Generate the output for the given (format, backends) pair.
 
     Parameters
     ----------
     fobj : file
         Event description file.
+    fname : str
+        Name of event file
 
     Returns a list of Event objects
     """
@@ -357,7 +359,7 @@ def read_events(fobj):
         try:
             event = Event.build(line)
         except ValueError as e:
-            arg0 = 'Error on line %d: %s' % (lineno, e.args[0])
+            arg0 = 'Error at %s:%d: %s' % (fname, lineno, e.args[0])
             e.args = (arg0,) + e.args[1:]
             raise
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] trace: include filename when printing parser error messages
  2018-03-06 15:46 [Qemu-devel] [PATCH] trace: include filename when printing parser error messages Daniel P. Berrangé
@ 2018-03-06 18:47 ` Philippe Mathieu-Daudé
  2018-03-08 15:21 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-03-06 18:47 UTC (permalink / raw)
  To: Daniel P. Berrangé, qemu-devel; +Cc: Stefan Hajnoczi

On 03/06/2018 12:46 PM, Daniel P. Berrangé wrote:
> Improves error messages from:
> 
>   ValueError: Error on line 72: need more than 1 value to unpack
> 
> To
> 
>   ValueError: Error at /home/berrange/src/virt/qemu/trace-events:72:
>     need more than 1 value to unpack
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  scripts/simpletrace.py        | 4 ++--
>  scripts/tracetool.py          | 2 +-
>  scripts/tracetool/__init__.py | 6 ++++--
>  3 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
> index a3a6315055..fefc0806b8 100755
> --- a/scripts/simpletrace.py
> +++ b/scripts/simpletrace.py
> @@ -168,7 +168,7 @@ class Analyzer(object):
>  def process(events, log, analyzer, read_header=True):
>      """Invoke an analyzer on each event in a log."""
>      if isinstance(events, str):
> -        events = read_events(open(events, 'r'))
> +        events = read_events(open(events, 'r'), events)
>      if isinstance(log, str):
>          log = open(log, 'rb')
>  
> @@ -233,7 +233,7 @@ def run(analyzer):
>                           '<trace-file>\n' % sys.argv[0])
>          sys.exit(1)
>  
> -    events = read_events(open(sys.argv[1], 'r'))
> +    events = read_events(open(sys.argv[1], 'r'), sys.argv[1])
>      process(events, sys.argv[2], analyzer, read_header=read_header)
>  
>  if __name__ == '__main__':
> diff --git a/scripts/tracetool.py b/scripts/tracetool.py
> index c55a21518b..fe2b0771f2 100755
> --- a/scripts/tracetool.py
> +++ b/scripts/tracetool.py
> @@ -142,7 +142,7 @@ def main(args):
>      events = []
>      for arg in args:
>          with open(arg, "r") as fh:
> -            events.extend(tracetool.read_events(fh))
> +            events.extend(tracetool.read_events(fh, arg))
>  
>      try:
>          tracetool.generate(events, arg_group, arg_format, arg_backends,
> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> index 52cc687ae3..b645be30d1 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -336,13 +336,15 @@ class Event(object):
>                       self)
>  
>  
> -def read_events(fobj):
> +def read_events(fobj, fname):
>      """Generate the output for the given (format, backends) pair.
>  
>      Parameters
>      ----------
>      fobj : file
>          Event description file.
> +    fname : str
> +        Name of event file
>  
>      Returns a list of Event objects
>      """
> @@ -357,7 +359,7 @@ def read_events(fobj):
>          try:
>              event = Event.build(line)
>          except ValueError as e:
> -            arg0 = 'Error on line %d: %s' % (lineno, e.args[0])
> +            arg0 = 'Error at %s:%d: %s' % (fname, lineno, e.args[0])
>              e.args = (arg0,) + e.args[1:]
>              raise
>  
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] trace: include filename when printing parser error messages
  2018-03-06 15:46 [Qemu-devel] [PATCH] trace: include filename when printing parser error messages Daniel P. Berrangé
  2018-03-06 18:47 ` Philippe Mathieu-Daudé
@ 2018-03-08 15:21 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2018-03-08 15:21 UTC (permalink / raw)
  To: Daniel P. Berrangé; +Cc: qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]

On Tue, Mar 06, 2018 at 03:46:50PM +0000, Daniel P. Berrangé wrote:
> Improves error messages from:
> 
>   ValueError: Error on line 72: need more than 1 value to unpack
> 
> To
> 
>   ValueError: Error at /home/berrange/src/virt/qemu/trace-events:72:
>     need more than 1 value to unpack
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/simpletrace.py        | 4 ++--
>  scripts/tracetool.py          | 2 +-
>  scripts/tracetool/__init__.py | 6 ++++--
>  3 files changed, 7 insertions(+), 5 deletions(-)

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-08 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-06 15:46 [Qemu-devel] [PATCH] trace: include filename when printing parser error messages Daniel P. Berrangé
2018-03-06 18:47 ` Philippe Mathieu-Daudé
2018-03-08 15:21 ` Stefan Hajnoczi

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 NNTP newsgroup(s).