ScriptExecutionError

Diagnostic signature

ScriptExecutionError

An exception class defined in CadQuery's CQGI (CadQuery Gateway Interface) subsystem that represents syntax or execution failures in CadQuery scripts, providing line and error message metadata for interactive host environments.

What it means

In CadQuery, ScriptExecutionError is part of the CadQuery Gateway Interface (cadquery.cqgi) and indicates that a provided script failed during parsing or execution. The exception encapsulates structured diagnostic metadata—namely the script line number (line) where the failure occurred and a descriptive message (message)—allowing execution environments such as CQ-editor, Sphinx documentation extensions, or automated export pipelines to report actionable error locations back to users.

Why it happens

The CQGI subsystem analyzes script source text using Python's Abstract Syntax Tree (ast) and executes it inside an isolated namespace constructed by EnvironmentBuilder. When the script contains invalid Python syntax (such as unbalanced parentheses, improper indentation, or syntax keywords used incorrectly) or encounters an unhandled runtime error during script evaluation, ScriptExecutionError is utilized to capture and convey the line number and exception details.

Minimal reproduction

import cadquery.cqgi as cqgi

# Malformed CadQuery script with an unclosed method call
invalid_script = """
import cadquery as cq

result = cq.Workplane("XY").box(10, 20, 30
show_object(result)
"""

try:
    cqgi.parse(invalid_script)
except SyntaxError as err:
    raise cqgi.ScriptExecutionError(line=err.lineno, message=err.msg) from err

How to fix it

Fix all syntax errors and runtime exceptions in the CadQuery script source so that AST parsing and CQGI model execution complete successfully.

```python
import cadquery.cqgi as cqgi

# Corrected script with valid Python syntax and CQGI show_object export
valid_script = """
import cadquery as cq

result = cq.Workplane("XY").box(10, 20, 30)
show_object(result)
"""

model = cqgi.parse(valid_script)
build_result = model.build()

if build_result.success:
    print(f"Build successful: generated {len(build_result.results)} object(s).")
else:
    raise build_result.exception

```

Step 1

Step 2

Step 3

Step 4

Upstream references

cadquery v2.7.0 — cadquery.cqgi.ScriptExecutionError — retrieved 2026-08-11

The CadQuery Gateway Interface — CadQuery Documentation