From nobody Sun Feb 8 16:32:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF57248867 for ; Mon, 19 Jan 2026 20:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768856347; cv=none; b=esxcs46ug10HiEyn1BPddqziSbvkuwtA7k0VvZLBG/MNm2B+Z9/1X/XIx8k+xt7AFr0qQpEr1dpDevCTCZsQkJmZhQkS0o6agBtEGqKfHpumjt/vkqWyAUgClfVgEwtF6V5feZ47lN8laiRW92GE8Os1O80bHV/kMvQunrrKOl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768856347; c=relaxed/simple; bh=QGcDYSWhPw0OsaIiT/Y79JYcZvgnZ1aoQ9w1dCfTLhM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lmqg8HZbbpV91oSbtoqEExwcIHI7byi3trqSZX+NgWCvEDTjJbOQD742BKFnYwqth6WWSCRRlDzKBJW0UdyH1OlIDH6SFWIpRRxVblSt2+LmBF92rHDSot5tGZxlNb00TKkWzYGFpe7EgIApDcpNTM+l/DDlEv0Sea4RHkQzgfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Fhy2oLii; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fhy2oLii" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768856344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yha+RfJYjyXBlkSkTQNuex11nXIbAhRh6al57WlRycU=; b=Fhy2oLii9o+JUznxXyFWwJE3YXWG0NFfF83qM4kQ+sLR9s/XZKYGOgt8OWLByBDZ3e4Ivm UBzybun+d/Rt+X1/qiXm2frikPFzqcBebz63LlYRr5Y7sdQF/KWvACYHgTRnGX5Jo7ckAz BUkn2YGSxGvsDooHM+/dh0KBI+eEEEg= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-r816YAYpPQKmogDGZ0ExdA-1; Mon, 19 Jan 2026 15:59:02 -0500 X-MC-Unique: r816YAYpPQKmogDGZ0ExdA-1 X-Mimecast-MFC-AGG-ID: r816YAYpPQKmogDGZ0ExdA_1768856341 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4522E1800378; Mon, 19 Jan 2026 20:59:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.137]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8F17419560AB; Mon, 19 Jan 2026 20:58:58 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Gabriele Monaco , Nam Cao , Wander Lairson Costa , linux-kernel@vger.kernel.org (open list), linux-trace-kernel@vger.kernel.org (open list:RUNTIME VERIFICATION (RV)) Subject: [PATCH 01/26] rv/rvgen: introduce AutomataError exception class Date: Mon, 19 Jan 2026 17:45:37 -0300 Message-ID: <20260119205601.105821-2-wander@redhat.com> In-Reply-To: <20260119205601.105821-1-wander@redhat.com> References: <20260119205601.105821-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Replace generic Exception usage with a custom AutomataError class that inherits from OSError throughout the rvgen tool. This change provides more precise exception handling for automata parsing and validation errors while avoiding overly broad exception catches that could mask programming errors like SyntaxError or TypeError. The AutomataError class inherits from OSError rather than Exception because most error conditions involve file I/O operations such as reading DOT files or handling file access issues. This semantic alignment makes exception handling more specific and appropriate. The exception is raised when DOT file processing fails due to invalid format, I/O errors, or malformed automaton definitions. Additionally, remove the broad try-except block from __main__.py that was catching all exceptions. This allows Python's default exception handling to provide complete stack traces, making debugging significantly easier by showing exact error types and locations. Signed-off-by: Wander Lairson Costa --- tools/verification/rvgen/__main__.py | 25 +++++++++------------ tools/verification/rvgen/rvgen/automata.py | 17 +++++++++----- tools/verification/rvgen/rvgen/dot2c.py | 4 ++-- tools/verification/rvgen/rvgen/generator.py | 7 ++---- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tools/verification/rvgen/__main__.py b/tools/verification/rvge= n/__main__.py index fa6fc1f4de2f7..768b11a1e978b 100644 --- a/tools/verification/rvgen/__main__.py +++ b/tools/verification/rvgen/__main__.py @@ -39,22 +39,17 @@ if __name__ =3D=3D '__main__': =20 params =3D parser.parse_args() =20 - try: - if params.subcmd =3D=3D "monitor": - print("Opening and parsing the specification file %s" % params= .spec) - if params.monitor_class =3D=3D "da": - monitor =3D dot2k(params.spec, params.monitor_type, vars(p= arams)) - elif params.monitor_class =3D=3D "ltl": - monitor =3D ltl2k(params.spec, params.monitor_type, vars(p= arams)) - else: - print("Unknown monitor class:", params.monitor_class) - sys.exit(1) + if params.subcmd =3D=3D "monitor": + print("Opening and parsing the specification file %s" % params.spe= c) + if params.monitor_class =3D=3D "da": + monitor =3D dot2k(params.spec, params.monitor_type, vars(param= s)) + elif params.monitor_class =3D=3D "ltl": + monitor =3D ltl2k(params.spec, params.monitor_type, vars(param= s)) else: - monitor =3D Container(vars(params)) - except Exception as e: - print('Error: '+ str(e)) - print("Sorry : :-(") - sys.exit(1) + print("Unknown monitor class:", params.monitor_class) + sys.exit(1) + else: + monitor =3D Container(vars(params)) =20 print("Writing the monitor into the directory %s" % monitor.name) monitor.print_files() diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verificatio= n/rvgen/rvgen/automata.py index d9a3fe2b74bf2..8d88c3b65d00d 100644 --- a/tools/verification/rvgen/rvgen/automata.py +++ b/tools/verification/rvgen/rvgen/automata.py @@ -10,6 +10,13 @@ =20 import ntpath =20 +class AutomataError(OSError): + """Exception raised for errors in automata parsing and validation. + + Raised when DOT file processing fails due to invalid format, I/O error= s, + or malformed automaton definitions. + """ + class Automata: """Automata class: Reads a dot file and part it as an automata. =20 @@ -32,11 +39,11 @@ class Automata: basename =3D ntpath.basename(self.__dot_path) if not basename.endswith(".dot") and not basename.endswith(".gv"): print("not a dot file") - raise Exception("not a dot file: %s" % self.__dot_path) + raise AutomataError("not a dot file: %s" % self.__dot_path) =20 model_name =3D ntpath.splitext(basename)[0] if model_name.__len__() =3D=3D 0: - raise Exception("not a dot file: %s" % self.__dot_path) + raise AutomataError("not a dot file: %s" % self.__dot_path) =20 return model_name =20 @@ -45,8 +52,8 @@ class Automata: dot_lines =3D [] try: dot_file =3D open(self.__dot_path) - except: - raise Exception("Cannot open the file: %s" % self.__dot_path) + except OSError as exc: + raise AutomataError(f"Cannot open the file: {self.__dot_path}"= ) from exc =20 dot_lines =3D dot_file.read().splitlines() dot_file.close() @@ -55,7 +62,7 @@ class Automata: line =3D dot_lines[cursor].split() =20 if (line[0] !=3D "digraph") and (line[1] !=3D "state_automaton"): - raise Exception("Not a valid .dot format: %s" % self.__dot_pat= h) + raise AutomataError("Not a valid .dot format: %s" % self.__dot= _path) else: cursor +=3D 1 return dot_lines diff --git a/tools/verification/rvgen/rvgen/dot2c.py b/tools/verification/r= vgen/rvgen/dot2c.py index b9b6f14cc536a..1a1770e7f20c0 100644 --- a/tools/verification/rvgen/rvgen/dot2c.py +++ b/tools/verification/rvgen/rvgen/dot2c.py @@ -13,7 +13,7 @@ # For further information, see: # Documentation/trace/rv/deterministic_automata.rst =20 -from .automata import Automata +from .automata import Automata, AutomataError =20 class Dot2c(Automata): enum_suffix =3D "" @@ -93,7 +93,7 @@ class Dot2c(Automata): min_type =3D "unsigned int" =20 if self.states.__len__() > 1000000: - raise Exception("Too many states: %d" % self.states.__len__()) + raise AutomataError("Too many states: %d" % self.states.__len_= _()) =20 return min_type =20 diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verificati= on/rvgen/rvgen/generator.py index 3441385c11770..a7bee6b1ea70c 100644 --- a/tools/verification/rvgen/rvgen/generator.py +++ b/tools/verification/rvgen/rvgen/generator.py @@ -51,10 +51,7 @@ class RVGenerator: raise FileNotFoundError("Could not find the rv directory, do you h= ave the kernel source installed?") =20 def _read_file(self, path): - try: - fd =3D open(path, 'r') - except OSError: - raise Exception("Cannot open the file: %s" % path) + fd =3D open(path, 'r') =20 content =3D fd.read() =20 @@ -65,7 +62,7 @@ class RVGenerator: try: path =3D os.path.join(self.abs_template_dir, file) return self._read_file(path) - except Exception: + except OSError: # Specific template file not found. Try the generic template f= ile in the template/ # directory, which is one level up path =3D os.path.join(self.abs_template_dir, "..", file) --=20 2.52.0