Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,25 @@
create_python_app,
print_env_info,
)
from create_python_app_core.errors import (
NON_EMPTY_DIR_ERROR_CODE,
ConfigParseError,
CpaError,
ManifestLoadError,
NonEmptyTargetDirectoryError,
PackageManagerFallbackError,
ScaffoldAbortedError,
)

__all__ = [
"__version__",
"CpaError",
"ConfigParseError",
"ManifestLoadError",
"PackageManagerFallbackError",
"ScaffoldAbortedError",
"NonEmptyTargetDirectoryError",
"NON_EMPTY_DIR_ERROR_CODE",
"CPA_USER_AGENT",
"check_for_latest_version",
"check_python_version",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
"""Typed CPA errors (mirrors create-node-app-core/errors.ts)."""

from __future__ import annotations


class CpaError(Exception):
"""Base error with a stable machine-readable code."""

code: str = "CPA_ERROR"

def __init__(self, message: str, *, code: str | None = None) -> None:
super().__init__(message)
if code is not None:
self.code = code


class ConfigParseError(CpaError):
code = "CPA_CONFIG_PARSE"


class ManifestLoadError(CpaError):
code = "CPA_MANIFEST_LOAD"


class PackageManagerFallbackError(CpaError):
code = "CPA_PM_FALLBACK"


class ScaffoldAbortedError(CpaError):
code = "CPA_ABORTED"


class NonEmptyTargetDirectoryError(CpaError):
code = "CPA_NON_EMPTY_TARGET_DIR"


NON_EMPTY_DIR_ERROR_CODE = NonEmptyTargetDirectoryError.code
12 changes: 12 additions & 0 deletions packages/create-python-app-core/tests/test_errors.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
from create_python_app_core import (
NON_EMPTY_DIR_ERROR_CODE,
ConfigParseError,
CpaError,
NonEmptyTargetDirectoryError,
)


def test_error_codes_use_cpa_prefix() -> None:
assert ConfigParseError("x").code.startswith("CPA_")
assert NonEmptyTargetDirectoryError("x").code == NON_EMPTY_DIR_ERROR_CODE
assert isinstance(ConfigParseError("x"), CpaError)