Skip to content

Errors

Import errors from rand_engine.validators.exceptions and catch RandEngineError when one recovery path covers the library's errors. More specific classes identify where the operation failed.

  • SpecValidationError reports RandSpec problems at construction or in a builder, before generation starts.
  • ColumnGenerationError wraps an exception raised while a validated generator method builds a named column.
  • TransformerError wraps an exception from a per-column transformer and names its column and position.
  • RandEngineError also covers output setup and writer failures such as a missing size, invalid writer option, schema mismatch or incompatible modifier.
  • FileWriterError is declared for callers that need the exception taxonomy, but no current library path raises it.
from rand_engine import DataGenerator
from rand_engine.validators.exceptions import RandEngineError, SpecValidationError

bad_spec = {"age": {"method": "not-a-method", "kwargs": {}}}
try:
    DataGenerator(bad_spec)
except SpecValidationError as error:
    assert "age" in str(error)
else:
    raise AssertionError("expected SpecValidationError")

spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
try:
    DataGenerator(spec).size(1).write.format("csv").option("engine", "fast").save("out/ages.csv")
except RandEngineError as error:
    assert "engine" in str(error)
else:
    raise AssertionError("expected RandEngineError")

Exception reference

Bases: Exception

Classe base para todas as exceções do Rand Engine.

Source code in rand_engine/validators/exceptions.py
 9
10
11
class RandEngineError(Exception):
    """Classe base para todas as exceções do Rand Engine."""
    pass