simics_package/error/
mod.rs

1// Copyright (C) 2024 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types
5
6use cargo_metadata::Target;
7use serde_json::Value;
8use std::path::PathBuf;
9
10#[derive(Debug, thiserror::Error)]
11/// An error raised during the packaging process
12pub enum Error {
13    #[error("No package {name} found in metadata")]
14    /// No package found in metadata
15    PackageNotFound {
16        /// Package name
17        name: String,
18    },
19    #[error("Invalid value build ID namespace {value:?} in 'package.metadata.simics.build-id-namespace = \"\"' field. Expected string.")]
20    /// Invalid value build ID namespace
21    InvalidBuildIdNamespace {
22        /// The invalid value
23        value: Value,
24    },
25    #[error("No package-number field found in metadata for {manifest}. Missing 'package.metadata.simics.package-number = 99999' to Cargo.toml?")]
26    /// No package number found in metadata
27    PackageNumberNotFound {
28        /// Path to the manifest
29        manifest: PathBuf,
30    },
31    #[error("Invalid package number {value} in 'package.metadata.simics.package-number = 99999' field. Expected integer.")]
32    /// Invalid package number
33    InvalidPackageNumber {
34        /// The invalid value
35        value: Value,
36    },
37    #[error("Invalid confidentiality {value:?} in 'package.metadata.simics.confidentiality = \"\"' field. Expected string.")]
38    /// Invalid confidentiality
39    InvalidConfidentiality {
40        /// The invalid value
41        value: Value,
42    },
43    #[error("Invalid access label {value:?} in 'package.metadata.simics.access-labels = [\"\", \"\"]' field. Expected string.")]
44    /// Invalid access label
45    InvalidAccessLabel {
46        /// The invalid value
47        value: Value,
48    },
49    #[error("No cdylib target in {targets:?}")]
50    /// No cdylib target found
51    CdylibTargetNotFound {
52        /// The set of targets not containing a cdylib
53        targets: Vec<Target>,
54    },
55    #[error("No parent found for path {path:?}")]
56    /// No parent found
57    ParentNotFound {
58        /// The path with missing parent
59        path: PathBuf,
60    },
61    #[error("No cdylib artifact found for {package:?}. Ensure the build succeeded and there is a [lib] entry in Cargo.toml with 'crate-type = [\"cdylib\"]'.")]
62    /// No cdylib artifact found
63    CdylibArtifactNotFound {
64        /// The package with no cdylib artifact
65        package: String,
66    },
67    #[error("Failed to convert path {path:?} to string")]
68    /// Failed to convert path to string
69    PathConversionError {
70        /// The path that could not be converted
71        path: PathBuf,
72    },
73    #[error("{path:?} is not a directory")]
74    /// Not a directory
75    NotADirectory {
76        /// The path that is not a directory
77        path: PathBuf,
78    },
79    #[error("Filename for {path:?} not found")]
80    /// Filename not found
81    FilenameNotFound {
82        /// The path with no filename
83        path: PathBuf,
84    },
85    #[error("Simics package metadata not found in manifest at {manifest_path:?}. Ensure there is a [package.metadata.simics] entry in Cargo.toml.")]
86    /// Simics package metadata not found
87    PackageMetadataNotFound {
88        /// The path to the manifest with no package metadata
89        manifest_path: PathBuf,
90    },
91    #[error("Package metadata field {field_name} missing")]
92    /// Package metadata field not found
93    PackageMetadataFieldNotFound {
94        /// The missing field name
95        field_name: String,
96    },
97    #[error("Package specifications is empty")]
98    /// Package specifications is empty
99    PackageSpecNotFound,
100    #[error("Error writing package file to {path:?}: {source}")]
101    /// Error writing package file
102    WritePackageError {
103        /// The path to the package file
104        path: PathBuf,
105        /// The underlying error
106        source: std::io::Error,
107    },
108    #[error("Non-addon type packages are not supported")]
109    /// Non-addon type packages are not supported
110    NonAddonPackage,
111    #[error(transparent)]
112    /// Cargo metadata error
113    CargoMetadataError(#[from] cargo_metadata::Error),
114    #[error(transparent)]
115    /// Parse integer error
116    ParseIntError(#[from] std::num::ParseIntError),
117    #[error(transparent)]
118    /// IO error
119    IoError(#[from] std::io::Error),
120    #[error(transparent)]
121    /// Strip prefix error
122    StripPrefixError(#[from] std::path::StripPrefixError),
123    #[error(transparent)]
124    /// Serde json error
125    SerdeJsonError(#[from] serde_json::Error),
126    #[error(transparent)]
127    /// Serde yaml error
128    SerdeYamlError(#[from] serde_yaml::Error),
129    #[error(transparent)]
130    /// Utf8 error
131    Utf8Error(#[from] std::str::Utf8Error),
132    #[error(transparent)]
133    /// System time error
134    SystemTimeError(#[from] std::time::SystemTimeError),
135}
136
137/// Simics packaging result type
138pub type Result<T> = std::result::Result<T, Error>;