Skip to content

Commit b267f33

Browse files
authored
Dependency: Upgrade ocipkg (#32)
* Remove thiserror usage. * Update ocipkg to v0.3.9 * Resolve breaking changes by bringing back `pull_layer_bytes()` * Re-apply clippy::result_large_err rule
1 parent 9179aa7 commit b267f33

File tree

7 files changed

+71
-66
lines changed

7 files changed

+71
-66
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
-D warnings \
4646
-W clippy::expect_used \
4747
-W clippy::uninlined_format_args \
48-
-W clippy::unwrap_used \
49-
-A clippy::result_large_err
48+
-W clippy::unwrap_used
5049
- name: Format Check
5150
run: cargo fmt -- --check --verbose

Cargo.lock

Lines changed: 30 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ env_logger = "0.11.3"
2626
human_format = "1.0.3"
2727
inquire = { version = "0.6.2", features = ["editor"] }
2828
log = "0.4.20"
29-
ocipkg = "0.2.9"
29+
ocipkg = "0.3.9"
3030
regex = "1.10.2"
3131
serde = { version = "1.0.188", features = ["derive"] }
3232
serde_json = { version = "1.0.107", features = ["preserve_order"] }
3333
serde_jsonc = { version = "1.0.107", features = ["preserve_order"] }
3434
tar = "0.4.40"
35-
thiserror = "1.0.52"
3635

3736
[target.'cfg(windows)'.dependencies]
3837
ascii_table = "4.0.3"

src/init.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,7 @@ pub struct InitArgs {
4747
workspace_folder: Option<PathBuf>,
4848
}
4949

50-
#[allow(clippy::enum_variant_names)]
51-
#[derive(thiserror::Error, Debug)]
52-
pub enum InitError {
53-
#[error(transparent)]
54-
ParseBoolError(#[from] std::str::ParseBoolError),
55-
#[error(transparent)]
56-
IOError(#[from] std::io::Error),
57-
#[error(transparent)]
58-
SystemTimeError(#[from] std::time::SystemTimeError),
59-
#[error(transparent)]
60-
RegexBuildError(#[from] regex::Error),
61-
#[error(transparent)]
62-
JsonError(#[from] serde_json::error::Error),
63-
#[error(transparent)]
64-
JsonWithCommentsError(#[from] serde_jsonc::error::Error),
65-
#[error(transparent)]
66-
PromptError(#[from] inquire::error::InquireError),
67-
#[error(transparent)]
68-
OciPkgError(#[from] ocipkg::error::Error),
69-
}
70-
71-
fn get_feature(
72-
index: &registry::DevcontainerIndex,
73-
feature_ref: &OciReference,
74-
) -> ocipkg::error::Result<registry::Feature> {
50+
fn get_feature(index: &registry::DevcontainerIndex, feature_ref: &OciReference) -> anyhow::Result<registry::Feature> {
7551
log::debug!("get_feature");
7652

7753
match index.get_feature(&feature_ref.id()) {
@@ -80,7 +56,7 @@ fn get_feature(
8056
}
8157
}
8258

83-
fn pull_feature_configuration(feature_ref: &OciReference) -> ocipkg::error::Result<registry::Feature> {
59+
fn pull_feature_configuration(feature_ref: &OciReference) -> anyhow::Result<registry::Feature> {
8460
log::debug!("pull_feature_configuration");
8561
let bytes = registry::pull_archive_bytes(feature_ref)?;
8662
let mut archive = Archive::new(bytes.as_slice());
@@ -186,7 +162,7 @@ impl<'t> DevOptionPrompt<'t> {
186162
}
187163
}
188164

189-
fn display_prompt(&self) -> Result<DevOptionPromptValue, InitError> {
165+
fn display_prompt(&self) -> anyhow::Result<DevOptionPromptValue> {
190166
let dev_option = self.inner;
191167
let default = dev_option.configured_default();
192168

@@ -296,7 +272,7 @@ impl FeatureEntryBuilder {
296272
}
297273
}
298274

299-
fn use_prompt_values(&mut self, feature: &registry::Feature) -> Result<(), InitError> {
275+
fn use_prompt_values(&mut self, feature: &registry::Feature) -> anyhow::Result<()> {
300276
log::debug!("FeatureEntryBuilder::use_prompt_values");
301277
let key = format!("{}:{}", feature.id, feature.major_version);
302278
let value = {
@@ -355,7 +331,7 @@ struct TemplateBuilder {
355331
}
356332

357333
impl TemplateBuilder {
358-
fn new(template_ref: &OciReference, config: Option<registry::Template>) -> ocipkg::error::Result<Self> {
334+
fn new(template_ref: &OciReference, config: Option<registry::Template>) -> anyhow::Result<Self> {
359335
log::debug!("TemplateBuilder::new");
360336
let archive_bytes = registry::pull_archive_bytes(template_ref)?;
361337
let template_archive = TemplateBuilder {
@@ -400,7 +376,7 @@ impl TemplateBuilder {
400376
))?
401377
}
402378

403-
fn use_prompt_values(&mut self) -> Result<(), InitError> {
379+
fn use_prompt_values(&mut self) -> anyhow::Result<()> {
404380
log::debug!("TemplateBuilder::use_prompt_values");
405381
let config = self
406382
.config
@@ -467,7 +443,7 @@ impl TemplateBuilder {
467443
false
468444
}
469445

470-
fn apply_context_and_features(&mut self, attempt_single_file: bool, workspace: &Path) -> Result<(), InitError> {
446+
fn apply_context_and_features(&mut self, attempt_single_file: bool, workspace: &Path) -> anyhow::Result<()> {
471447
log::debug!("TemplateBuilder::apply_context_and_features");
472448
let template_option_re = Regex::new(r"\$\{templateOption:\s*(?<name>\w+)\s*\}")?;
473449
let apply_context = |captures: &Captures| -> &[u8] {
@@ -564,7 +540,7 @@ impl TemplateBuilder {
564540
Ok(())
565541
}
566542

567-
fn create_empty_start_point() -> Result<Self, InitError> {
543+
fn create_empty_start_point() -> anyhow::Result<Self> {
568544
let template_value = serde_json::json!({
569545
"id": "tyedev-base-template",
570546
"version": "1.0.0",
@@ -712,7 +688,7 @@ pub fn init(
712688
include_deprecated,
713689
workspace_folder,
714690
}: InitArgs,
715-
) -> Result<(), InitError> {
691+
) -> anyhow::Result<()> {
716692
log::debug!("init");
717693
// Do this evaluation of the `env` first so that it can error early.
718694
let workspace = workspace_folder.map_or_else(env::current_dir, Ok)?;
@@ -835,7 +811,7 @@ pub fn init(
835811
// TODO these are more *proof of concept* than actual tests...
836812
#[cfg(test)]
837813
mod tests {
838-
use super::{FeatureEntryBuilder, InitError, TemplateBuilder};
814+
use super::{FeatureEntryBuilder, TemplateBuilder};
839815
use serde_json::{self, Map, Value};
840816

841817
#[test]
@@ -859,7 +835,7 @@ mod tests {
859835
}
860836

861837
#[test]
862-
fn test_create_empty_start_point() -> Result<(), InitError> {
838+
fn test_create_empty_start_point() -> anyhow::Result<()> {
863839
let _template_builder = TemplateBuilder::create_empty_start_point()?;
864840
Ok(())
865841
}

src/inspect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn display<T: ?Sized + Displayable>(value: &T, format: &InspectDisplay) -> serde
217217
Ok(())
218218
}
219219

220-
fn display_files(oci_ref: &OciReference) -> ocipkg::error::Result<()> {
220+
fn display_files(oci_ref: &OciReference) -> anyhow::Result<()> {
221221
log::debug!("display_files");
222222

223223
let bytes = registry::pull_archive_bytes(oci_ref)?;
@@ -241,7 +241,7 @@ fn display_files(oci_ref: &OciReference) -> ocipkg::error::Result<()> {
241241
Ok(())
242242
}
243243

244-
fn display_install_sh(oci_ref: &OciReference) -> ocipkg::error::Result<()> {
244+
fn display_install_sh(oci_ref: &OciReference) -> anyhow::Result<()> {
245245
log::debug!("display_install_sh");
246246

247247
let bytes = registry::pull_archive_bytes(oci_ref)?;
@@ -276,7 +276,7 @@ pub fn inspect(
276276
install_sh,
277277
show_files,
278278
}: InspectArgs,
279-
) -> ocipkg::error::Result<()> {
279+
) -> anyhow::Result<()> {
280280
log::debug!("inspect");
281281

282282
let id = oci_ref.id();

src/oci_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl OciReference {
1818
}
1919

2020
impl FromStr for OciReference {
21-
type Err = ocipkg::error::Error;
21+
type Err = anyhow::Error;
2222

2323
fn from_str(name: &str) -> Result<Self, Self::Err> {
2424
ImageName::parse(name).map(OciReference)
@@ -28,7 +28,7 @@ impl FromStr for OciReference {
2828
#[cfg(test)]
2929
mod tests {
3030
use super::OciReference;
31-
use ocipkg::error::Result;
31+
use anyhow::Result;
3232

3333
#[test]
3434
fn test_parse() -> Result<()> {

0 commit comments

Comments
 (0)