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