pub enum AgpmError {
Show 37 variants
GitCommandError {
operation: String,
stderr: String,
},
GitNotFound,
GitRepoInvalid {
path: String,
},
GitAuthenticationFailed {
url: String,
},
GitCloneFailed {
url: String,
reason: String,
},
GitCheckoutFailed {
reference: String,
reason: String,
},
ConfigError {
message: String,
},
ManifestNotFound,
ManifestParseError {
file: String,
reason: String,
},
ManifestValidationError {
reason: String,
},
LockfileParseError {
file: String,
reason: String,
},
ResourceNotFound {
name: String,
},
ResourceFileNotFound {
path: String,
source_name: String,
},
SourceNotFound {
name: String,
},
SourceUnreachable {
name: String,
url: String,
},
InvalidVersionConstraint {
constraint: String,
},
VersionNotFound {
resource: String,
version: String,
},
AlreadyInstalled {
name: String,
},
InvalidResourceType {
resource_type: String,
},
InvalidResourceStructure {
file: String,
reason: String,
},
CircularDependency {
chain: String,
},
DependencyResolutionFailed {
reason: String,
},
NetworkError {
operation: String,
reason: String,
},
FileSystemError {
operation: String,
path: String,
},
PermissionDenied {
operation: String,
path: String,
},
DirectoryNotEmpty {
path: String,
},
InvalidDependency {
name: String,
reason: String,
},
InvalidResource {
name: String,
reason: String,
},
DependencyNotMet {
name: String,
required: String,
found: String,
},
ConfigNotFound {
path: String,
},
ChecksumMismatch {
name: String,
expected: String,
actual: String,
},
PlatformNotSupported {
operation: String,
},
IoError(Error),
TomlError(Error),
TomlSerError(Error),
SemverError(Error),
Other {
message: String,
},
}
Expand description
The main error type for AGPM operations
This enum represents all possible errors that can occur during AGPM operations. Each variant is designed to provide specific context about the failure and enable appropriate error handling strategies.
§Design Philosophy
- Specific Error Types: Each error variant represents a specific failure mode
- Rich Context: Errors include relevant details like file paths, URLs, and reasons
- User-Friendly: Error messages are written for end users, not just developers
- Actionable: Most errors provide clear guidance on how to resolve the issue
§Error Categories
§Git Operations
GitNotFound
- Git executable not availableGitCommandError
- Git command execution failedGitAuthenticationFailed
- Git authentication problemsGitCloneFailed
- Repository cloning failedGitCheckoutFailed
- Git checkout operation failed
§File System Operations
FileSystemError
- General file system operationsPermissionDenied
- Insufficient permissionsDirectoryNotEmpty
- Directory contains files when empty expectedIoError
- Standard I/O errors fromstd::io::Error
§Configuration and Parsing
ManifestNotFound
- agpm.toml file missingManifestParseError
- Invalid TOML syntax in manifestManifestValidationError
- Manifest content validation failedLockfileParseError
- Invalid lockfile formatConfigError
- Configuration file issuesTomlError
- TOML parsing errors fromtoml::de::Error
TomlSerError
- TOML serialization errors fromtoml::ser::Error
§Resource Management
ResourceNotFound
- Named resource doesn’t existResourceFileNotFound
- Resource file missing from repositoryInvalidResourceType
- Unknown resource type specifiedInvalidResourceStructure
- Resource content is malformedInvalidResource
- Resource validation failedAlreadyInstalled
- Resource already exists
§Dependency Resolution
CircularDependency
- Dependency cycle detectedDependencyResolutionFailed
- Cannot resolve dependenciesDependencyNotMet
- Version constraint not satisfiedInvalidDependency
- Malformed dependency specificationInvalidVersionConstraint
- Invalid version formatVersionNotFound
- Requested version doesn’t existSemverError
- Semantic version parsing fromsemver::Error
§Source Management
SourceNotFound
- Named source not definedSourceUnreachable
- Cannot connect to source repository
§Platform and Network
NetworkError
- Network connectivity issuesPlatformNotSupported
- Operation not supported on current platformChecksumMismatch
- File integrity verification failed
§Examples
§Pattern Matching on Errors
use agpm_cli::core::AgpmError;
fn handle_error(error: AgpmError) {
match error {
AgpmError::GitNotFound => {
eprintln!("Please install git to use AGPM");
std::process::exit(1);
}
AgpmError::ManifestNotFound => {
eprintln!("Run 'agpm init' to create a manifest file");
}
AgpmError::NetworkError { operation, .. } => {
eprintln!("Network error during {}: check your connection", operation);
}
_ => {
eprintln!("Unexpected error: {}", error);
}
}
}
§Creating Specific Errors
use agpm_cli::core::AgpmError;
// Create a git command error with context
let error = AgpmError::GitCommandError {
operation: "clone".to_string(),
stderr: "repository not found".to_string(),
};
// Create a resource not found error
let error = AgpmError::ResourceNotFound {
name: "my-agent".to_string(),
};
// Create a version constraint error
let error = AgpmError::InvalidVersionConstraint {
constraint: "~1.x.y".to_string(),
};
Variants§
GitCommandError
Git operation failed during execution
This error occurs when a git command returns a non-zero exit code. Common causes include network issues, authentication problems, or invalid git repository states.
§Fields
operation
: The git operation that failed (e.g., “clone”, “fetch”, “checkout”)stderr
: The error output from the git command
Fields
GitNotFound
Git executable not found in PATH
This error occurs when AGPM cannot locate the git
command in the system PATH.
AGPM requires git to be installed and available for repository operations.
Common solutions:
- Install git from https://git-scm.com/
- Use a package manager:
brew install git
,apt install git
, etc. - Ensure git is in your PATH environment variable
GitRepoInvalid
Git repository is invalid or corrupted
This error occurs when a directory exists but doesn’t contain a valid git repository structure (missing .git directory or corrupted).
§Fields
path
: The path that was expected to contain a git repository
GitAuthenticationFailed
Git authentication failed for repository access
This error occurs when git cannot authenticate with a remote repository. Common for private repositories or when credentials are missing/expired.
§Fields
url
: The repository URL that failed authentication
GitCloneFailed
Git repository clone failed
Fields
GitCheckoutFailed
Git checkout failed
Fields
ConfigError
Configuration error
ManifestNotFound
Manifest file (agpm.toml) not found
This error occurs when AGPM cannot locate a agpm.toml file in the current directory or any parent directory up to the filesystem root.
AGPM searches for agpm.toml starting from the current working directory and walking up the directory tree, similar to how git searches for .git.
ManifestParseError
Manifest parsing error
Fields
ManifestValidationError
Manifest validation error
LockfileParseError
Lockfile parsing error
Fields
ResourceNotFound
Resource not found
ResourceFileNotFound
Resource file not found in repository
Fields
SourceNotFound
Source repository not found
SourceUnreachable
Source repository unreachable
InvalidVersionConstraint
Invalid version constraint
VersionNotFound
Version not found
Fields
AlreadyInstalled
Resource already installed
InvalidResourceType
Invalid resource type
InvalidResourceStructure
Invalid resource structure
Fields
CircularDependency
Circular dependency detected in dependency graph
This error occurs when resources depend on each other in a cycle, making it impossible to determine installation order.
Example: A depends on B, B depends on C, C depends on A
§Fields
chain
: The dependency chain showing the circular reference
DependencyResolutionFailed
Dependency resolution failed
NetworkError
Network error
Fields
FileSystemError
File system error
Fields
PermissionDenied
Permission denied
Fields
DirectoryNotEmpty
Directory not empty
InvalidDependency
Invalid dependency specification
Fields
InvalidResource
Invalid resource content
Fields
DependencyNotMet
Dependency not met
Fields
ConfigNotFound
Config file not found
ChecksumMismatch
Checksum mismatch
Fields
PlatformNotSupported
Platform not supported
IoError(Error)
IO error
TomlError(Error)
TOML parsing error
TomlSerError(Error)
TOML serialization error
SemverError(Error)
Semver parsing error
Other
Other error
Trait Implementations§
Source§impl Error for AgpmError
impl Error for AgpmError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl IntoAnyhowWithContext for AgpmError
impl IntoAnyhowWithContext for AgpmError
Source§fn into_anyhow_with_context(self, context: ErrorContext) -> Error
fn into_anyhow_with_context(self, context: ErrorContext) -> Error
anyhow::Error
with the provided contextAuto Trait Implementations§
impl Freeze for AgpmError
impl !RefUnwindSafe for AgpmError
impl Send for AgpmError
impl Sync for AgpmError
impl Unpin for AgpmError
impl !UnwindSafe for AgpmError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.