cadquery.cqgi.InvalidParameterError

Diagnostic signature

InvalidParameterError

An error raised by the CadQuery Gateway Interface (CQGI) when an execution environment provides a parameter override value that cannot be coerced to the expected type or violates defined parameter constraints.

What it means

The CadQuery Gateway Interface (CQGI) standardizes how execution environments (like CQ-editor or custom Python containers) interact with CadQuery scripts. During script parsing, CQGI inspects the script's abstract syntax tree (AST) to discover top-level variable definitions, their inferred data types (such as `NumberParameterType` or `StringParameterType`), and any constraints provided via `describe_parameter()`. When the execution environment subsequently attempts to execute the script with overridden values via `CQModel.build(build_parameters=...)`, CQGI validates the overrides against the discovered parameters. The `InvalidParameterError` signifies that at least one of the supplied override values in the `build_parameters` dictionary was rejected. This rejection occurs because the value could not be successfully cast to the target type, or because it fell outside the set of permitted values defined in the script's metadata.

Why it happens

This diagnostic is typically emitted for one of the following reasons: 1. **Type Coercion Failure:** The host environment passes an override value that cannot be converted to the type of the default value found in the script. For example, if a script initializes `width = 10.0` (making it a number), and the execution environment passes the string `"invalid_string"` via `build_parameters`, the underlying `float()` coercion raises a `ValueError`, which CQGI catches and re-raises as an `InvalidParameterError`. 2. **Constraint Violation:** The script explicitly restricts a parameter's allowed values using the CQGI `describe_parameter(...)` function (e.g., providing a specific list of `valid_values`). If the overriding value passed by the environment is not among this permitted set, the validation check fails and the same error is emitted. 3. **Undeclared Parameter:** The host environment attempts to provide a value for a parameter name that was never defined as a top-level variable in the underlying model.

Minimal reproduction

import cadquery as cq
import cadquery.cqgi as cqgi

# Define a minimal script with a numeric parameter
script_source = """
import cadquery as cq

# 'width' is inferred as a NumberParameterType
width = 10.0

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

# Parse the script using CQGI
model = cqgi.parse(script_source)

# Attempt to build the model by providing a string instead of a float
# This will fail to coerce and raise InvalidParameterError
build_result = model.build(build_parameters={"width": "invalid_string"})

if not build_result.success:
    raise build_result.exception

How to fix it

Ensure that all parameter overrides passed via `build_parameters` match the inferred data types of the script's top-level variables and respect any constraints defined by `describe_parameter()`.

```python
import cadquery as cq
import cadquery.cqgi as cqgi

script_source = """
import cadquery as cq

# 'width' is inferred as a NumberParameterType
width = 10.0

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

model = cqgi.parse(script_source)

# Provide a valid float parameter override instead of a string
build_result = model.build(build_parameters={"width": 15.5})

if build_result.success:
    print("Build successful!")
else:
    raise build_result.exception

```

Step 1

Step 2

Step 3

Upstream references

The CadQuery Gateway Interface

Source code for cadquery.cqgi