API/Error Handling

CLI and Errors

Error Handling

Understand the exception hierarchy, error codes, and recommended caller behavior.

Apart from ordinary OSError, ValueError, and FileExistsError boundaries, every public OCTX exception inherits from OctxError and provides a stable code. Most exceptions also carry an optional path.

Exception hierarchy

ExceptionDefault error codeWhen it occurs
OctxErrorOCTX_ERRORBase class for all OCTX operation exceptions.
OctxOpenErrorOCTX_OPEN_ERRORBase class for failures to open a Package.
OctxFormatErrorOCTX_FORMAT_ERRORCorrupt ZIP, manifest, JSON, encoding, or payload format; specific instances may use more specific error codes.
OctxSecurityErrorOCTX_SECURITY_ERRORUnsafe paths, links, encrypted entries, source replacement, or another security violation.
OctxResourceLimitErrorOCTX_RESOURCE_LIMITInput exceeds ArchiveLimits.
OctxIntegrityErrorOCTX_INTEGRITY_ERRORAn integrity operation fails.
OctxValidationErrorOCTX_VALIDATION_ERRORCreation or unpacking requires a valid Package, but full validation fails.
ReleaseVersionErrorOCTX_RELEASE_VERSION_REQUIREDAn old version is reused after content changes, or the new version does not move forward.
DerivationRequiredOCTX_DERIVATION_REQUIREDAn external Package is modified without explicitly creating a derived Asset.
OutputExistsErrorOCTX_OUTPUT_EXISTSThe output path already contains a different immutable Package.
python
from octx import (
    OctxError,
    OutputExistsError,
    ReleaseVersionError,
    create_octx,
)

try:
    result = create_octx(...)
except OutputExistsError:
    # Do not overwrite a different immutable Package that already exists.
    raise
except ReleaseVersionError:
    # Increase the Release version, then retry.
    raise
except OctxError as error:
    log(error.code, error.path, str(error))
    raise

OctxValidationError.report contains the complete ValidationReport:

python
from octx import OctxValidationError, unpack_octx

try:
    unpack_octx("asset.octx", "./expanded")
except OctxValidationError as error:
    print(error.report.to_dict())

Validation is not exception flow

When processing untrusted input, prefer calling validate_octx() directly. Ordinary ZIP, format, digest, and structural errors are converted into a report with valid=False:

python
report = validate_octx("upload.octx")
if not report.valid:
    return {"accepted": False, "validation": report.to_dict()}

Only invalid arguments themselves, such as max_issues <= 0, continue to raise ValueError.