Skip to content

Commit c70c208

Browse files
Arm backend: Convert assert to throw ValueError in tosa_backend (#9905)
There's a risk with using asserts in production code as it might get optimized out. A proper error is raised instead. Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent 2b4e525 commit c70c208

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: backends/arm/tosa_backend.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ def preprocess( # noqa: C901
7575
input_order = list(map(int, spec.value.decode().split(",")))
7676

7777
# Check that the output format is set correctly in the compile spec
78-
assert output_format == "tosa", "output format must be tosa"
78+
if output_format != "tosa":
79+
raise ValueError(f'Invalid output format {output_format}, must be "tosa"')
7980

8081
tosa_spec = get_tosa_spec(compile_spec)
81-
assert (
82-
tosa_spec is not None
83-
), "TOSA backend needs a TOSA version specified in the CompileSpec!"
82+
if tosa_spec is None:
83+
raise ValueError(
84+
"TOSA backend needs a TOSA version specified in the CompileSpec"
85+
)
8486

8587
logger.info(f"Converting ExportedProgram to TOSA: {tosa_spec}")
8688

0 commit comments

Comments
 (0)