From 5b6fa3eaf72a696aa9ffdf7299461c0d6db14169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Sun, 8 Jun 2025 00:40:29 +0000 Subject: [PATCH] minor imports refactoring --- Cargo.lock | 27 ++++++++++++++++++++++++--- Cargo.toml | 1 + src/sharry/api.rs | 6 +++--- src/sharry/file/uploading.rs | 22 +++++++++++++++++----- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53700b9..8794b6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -236,7 +236,7 @@ checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" dependencies = [ "console", "shell-words", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -702,7 +702,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -856,6 +856,7 @@ dependencies = [ "log", "serde", "serde_json", + "thiserror 2.0.12", "ureq", ] @@ -911,7 +912,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -925,6 +935,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "time" version = "0.3.41" diff --git a/Cargo.toml b/Cargo.toml index eca8b13..f1fec53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ indicatif = { version = "0.17.11", default-features = false } log = "0.4.27" serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" +thiserror = "2.0.12" ureq = { version = "3.0.11", features = ["json"] } [profile.release] diff --git a/src/sharry/api.rs b/src/sharry/api.rs index 8d18ecf..0898bf1 100644 --- a/src/sharry/api.rs +++ b/src/sharry/api.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use std::fmt; use serde::{Deserialize, Serialize}; @@ -17,8 +17,8 @@ impl Uri { } } -impl Display for Uri { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for Uri { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}://{}/api/v2", self.protocol, self.base_url) } } diff --git a/src/sharry/file/uploading.rs b/src/sharry/file/uploading.rs index f243d18..3109a0a 100644 --- a/src/sharry/file/uploading.rs +++ b/src/sharry/file/uploading.rs @@ -1,6 +1,6 @@ use std::{ ffi::OsStr, - fs, + fmt, fs, io::{self, Read, Seek, SeekFrom}, path::PathBuf, }; @@ -19,12 +19,24 @@ pub struct FileUploading { offset: u64, } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum UploadError { - FileIO(io::Error), + #[error("file I/O error: {0}")] + FileIO(#[from] io::Error), + + #[error("network request failed")] Request, + + #[error("unexpected response status")] ResponseStatus, + + #[error("could not parse offset header")] ResponseOffset, + // #[error("chunk length conversion failed: {0}")] + // InvalidChunkLength(String), + + // #[error("offset mismatch")] + // ResponseOffsetMismatch, } pub enum ChunkState { @@ -33,8 +45,8 @@ pub enum ChunkState { Finished(PathBuf), } -impl std::fmt::Display for FileUploading { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for FileUploading { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Uploading {:?} ({}/{})",