use cargo_metadata::Target;
use serde_json::Value;
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("No package {name} found in metadata")]
PackageNotFound {
name: String,
},
#[error("Invalid value build ID namespace {value:?} in 'package.metadata.simics.build-id-namespace = \"\"' field. Expected string.")]
InvalidBuildIdNamespace {
value: Value,
},
#[error("No package-number field found in metadata for {manifest}. Missing 'package.metadata.simics.package-number = 99999' to Cargo.toml?")]
PackageNumberNotFound {
manifest: PathBuf,
},
#[error("Invalid package number {value} in 'package.metadata.simics.package-number = 99999' field. Expected integer.")]
InvalidPackageNumber {
value: Value,
},
#[error("Invalid confidentiality {value:?} in 'package.metadata.simics.confidentiality = \"\"' field. Expected string.")]
InvalidConfidentiality {
value: Value,
},
#[error("Invalid access label {value:?} in 'package.metadata.simics.access-labels = [\"\", \"\"]' field. Expected string.")]
InvalidAccessLabel {
value: Value,
},
#[error("No cdylib target in {targets:?}")]
CdylibTargetNotFound {
targets: Vec<Target>,
},
#[error("No parent found for path {path:?}")]
ParentNotFound {
path: PathBuf,
},
#[error("No cdylib artifact found for {package:?}. Ensure the build succeeded and there is a [lib] entry in Cargo.toml with 'crate-type = [\"cdylib\"]'.")]
CdylibArtifactNotFound {
package: String,
},
#[error("Failed to convert path {path:?} to string")]
PathConversionError {
path: PathBuf,
},
#[error("{path:?} is not a directory")]
NotADirectory {
path: PathBuf,
},
#[error("Filename for {path:?} not found")]
FilenameNotFound {
path: PathBuf,
},
#[error("Simics package metadata not found in manifest at {manifest_path:?}. Ensure there is a [package.metadata.simics] entry in Cargo.toml.")]
PackageMetadataNotFound {
manifest_path: PathBuf,
},
#[error("Package metadata field {field_name} missing")]
PackageMetadataFieldNotFound {
field_name: String,
},
#[error("Package specifications is empty")]
PackageSpecNotFound,
#[error("Error writing package file to {path:?}: {source}")]
WritePackageError {
path: PathBuf,
source: std::io::Error,
},
#[error("Non-addon type packages are not supported")]
NonAddonPackage,
#[error(transparent)]
CargoMetadataError(#[from] cargo_metadata::Error),
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error(transparent)]
StripPrefixError(#[from] std::path::StripPrefixError),
#[error(transparent)]
SerdeJsonError(#[from] serde_json::Error),
#[error(transparent)]
SerdeYamlError(#[from] serde_yaml::Error),
#[error(transparent)]
Utf8Error(#[from] std::str::Utf8Error),
#[error(transparent)]
SystemTimeError(#[from] std::time::SystemTimeError),
}
pub type Result<T> = std::result::Result<T, Error>;