gabriel / muse public
errors.py python
37 lines 989 B
e6786943 feat: upgrade to Python 3.14, drop from __future__ import annotations Gabriel Cardona <cgcardona@gmail.com> 5d ago
1 """Exit-code contract and exception types for the Muse CLI."""
2
3 import enum
4
5
6 class ExitCode(enum.IntEnum):
7 """Standardised CLI exit codes.
8
9 0 — success
10 1 — user error (bad arguments, invalid input)
11 2 — repo-not-found / config invalid
12 3 — server / internal error
13 """
14
15 SUCCESS = 0
16 USER_ERROR = 1
17 REPO_NOT_FOUND = 2
18 INTERNAL_ERROR = 3
19
20
21 class MuseCLIError(Exception):
22 """Base exception for Muse CLI errors."""
23
24 def __init__(self, message: str, exit_code: ExitCode = ExitCode.INTERNAL_ERROR) -> None:
25 super().__init__(message)
26 self.exit_code = exit_code
27
28
29 class RepoNotFoundError(MuseCLIError):
30 """Raised when the current directory is not a Muse repository."""
31
32 def __init__(self, message: str = "Not a Muse repository. Run `muse init`.") -> None:
33 super().__init__(message, exit_code=ExitCode.REPO_NOT_FOUND)
34
35
36 #: Canonical public alias matching the name specified.
37 MuseNotARepoError = RepoNotFoundError