From 25d54654da2a2d1c612c827e6155d3bec0e1201f Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 25 Jan 2017 16:14:17 +0000 Subject: trace: improve error reporting when parsing simpletrace header When loading a simpletrace binary file we just report "Not a valid trace file!" which is not very helpful. Report exactly which field we found to be invalid. Reviewed-by: Stefan Hajnoczi Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170125161417.31949-9-berrange@redhat.com Signed-off-by: Stefan Hajnoczi --- scripts/simpletrace.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 4ca903dc0c..4c990047b6 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -73,10 +73,14 @@ def read_record(edict, idtoname, fobj): def read_trace_header(fobj): """Read and verify trace file header""" header = read_header(fobj, log_header_fmt) - if header is None or \ - header[0] != header_event_id or \ - header[1] != header_magic: + if header is None: raise ValueError('Not a valid trace file!') + if header[0] != header_event_id: + raise ValueError('Not a valid trace file, header id %d != %d' % + (header[0], header_event_id)) + if header[1] != header_magic: + raise ValueError('Not a valid trace file, header magic %d != %d' % + (header[1], header_magic)) log_version = header[2] if log_version not in [0, 2, 3, 4]: -- cgit v1.2.3