From 0d0082523400159503a7fbf5819eb415f72e322b Mon Sep 17 00:00:00 2001 From: Sebastian Larsson Date: Wed, 2 Apr 2025 13:56:24 +0200 Subject: [PATCH] Arm backend: Convert assert to throw ValueError in tosa_backend There's a risk with using asserts in production code as it might get optimized out. A proper error is raised instead. Change-Id: Ie10348c65c3d45a4773efbbcbc0686cd9007b800 Signed-off-by: Sebastian Larsson --- backends/arm/tosa_backend.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backends/arm/tosa_backend.py b/backends/arm/tosa_backend.py index 3f9c7755f83..314f4c7d291 100644 --- a/backends/arm/tosa_backend.py +++ b/backends/arm/tosa_backend.py @@ -75,12 +75,14 @@ def preprocess( # noqa: C901 input_order = list(map(int, spec.value.decode().split(","))) # Check that the output format is set correctly in the compile spec - assert output_format == "tosa", "output format must be tosa" + if output_format != "tosa": + raise ValueError(f'Invalid output format {output_format}, must be "tosa"') tosa_spec = get_tosa_spec(compile_spec) - assert ( - tosa_spec is not None - ), "TOSA backend needs a TOSA version specified in the CompileSpec!" + if tosa_spec is None: + raise ValueError( + "TOSA backend needs a TOSA version specified in the CompileSpec" + ) logger.info(f"Converting ExportedProgram to TOSA: {tosa_spec}")