Skip to content

Commit 4a399cd

Browse files
committed
Remove anyhow::Result for lock serialization
1 parent facd21a commit 4a399cd

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-resolver/src/lock/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use itertools::Itertools;
1111
use petgraph::graph::NodeIndex;
1212
use petgraph::visit::EdgeRef;
1313
use rustc_hash::{FxHashMap, FxHashSet};
14+
use serde::Serializer;
1415
use toml_edit::{value, Array, ArrayOfTables, InlineTable, Item, Table, Value};
1516
use url::Url;
1617

@@ -617,7 +618,7 @@ impl Lock {
617618
}
618619

619620
/// Returns the TOML representation of this lockfile.
620-
pub fn to_toml(&self) -> anyhow::Result<String> {
621+
pub fn to_toml(&self) -> Result<String, toml_edit::ser::Error> {
621622
// We construct a TOML document manually instead of going through Serde to enable
622623
// the use of inline tables.
623624
let mut doc = toml_edit::DocumentMut::new();
@@ -2085,7 +2086,7 @@ impl Package {
20852086
&self,
20862087
requires_python: &RequiresPython,
20872088
dist_count_by_name: &FxHashMap<PackageName, u64>,
2088-
) -> anyhow::Result<Table> {
2089+
) -> Result<Table, toml_edit::ser::Error> {
20892090
let mut table = Table::new();
20902091

20912092
self.id.to_toml(None, &mut table);
@@ -2149,7 +2150,7 @@ impl Package {
21492150
self.wheels
21502151
.iter()
21512152
.map(Wheel::to_toml)
2152-
.collect::<anyhow::Result<Vec<_>>>()?
2153+
.collect::<Result<Vec<_>, _>>()?
21532154
.into_iter(),
21542155
);
21552156
table.insert("wheels", value(wheels));
@@ -3224,7 +3225,7 @@ enum SourceDistWire {
32243225

32253226
impl SourceDist {
32263227
/// Returns the TOML representation of this source distribution.
3227-
fn to_toml(&self) -> anyhow::Result<InlineTable> {
3228+
fn to_toml(&self) -> Result<InlineTable, toml_edit::ser::Error> {
32283229
let mut table = InlineTable::new();
32293230
match &self {
32303231
SourceDist::Metadata { .. } => {}
@@ -3239,7 +3240,10 @@ impl SourceDist {
32393240
table.insert("hash", Value::from(hash.to_string()));
32403241
}
32413242
if let Some(size) = self.size() {
3242-
table.insert("size", Value::from(i64::try_from(size)?));
3243+
table.insert(
3244+
"size",
3245+
toml_edit::ser::ValueSerializer::new().serialize_u64(size)?,
3246+
);
32433247
}
32443248
Ok(table)
32453249
}
@@ -3612,7 +3616,7 @@ enum WheelWireSource {
36123616

36133617
impl Wheel {
36143618
/// Returns the TOML representation of this wheel.
3615-
fn to_toml(&self) -> anyhow::Result<InlineTable> {
3619+
fn to_toml(&self) -> Result<InlineTable, toml_edit::ser::Error> {
36163620
let mut table = InlineTable::new();
36173621
match &self.url {
36183622
WheelWireSource::Url { url } => {
@@ -3629,7 +3633,10 @@ impl Wheel {
36293633
table.insert("hash", Value::from(hash.to_string()));
36303634
}
36313635
if let Some(size) = self.size {
3632-
table.insert("size", Value::from(i64::try_from(size)?));
3636+
table.insert(
3637+
"size",
3638+
toml_edit::ser::ValueSerializer::new().serialize_u64(size)?,
3639+
);
36333640
}
36343641
Ok(table)
36353642
}

crates/uv/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ textwrap = { workspace = true }
8888
thiserror = { workspace = true }
8989
tokio = { workspace = true }
9090
toml = { workspace = true }
91+
toml_edit = { workspace = true }
9192
tracing = { workspace = true }
9293
tracing-durations-export = { workspace = true, features = ["plot"], optional = true }
9394
tracing-subscriber = { workspace = true, features = ["json"] }

crates/uv/src/commands/project/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ pub(crate) enum ProjectError {
7878
#[error("Failed to parse `uv.lock`, which uses an unsupported schema version (v{1}, but only v{0} is supported). Downgrade to a compatible uv version, or remove the `uv.lock` prior to running `uv lock` or `uv sync`.")]
7979
UnparsableLockVersion(u32, u32, #[source] toml::de::Error),
8080

81+
#[error("Failed to serialize `uv.lock`")]
82+
LockSerialization(#[from] toml_edit::ser::Error),
83+
8184
#[error("The current Python version ({0}) is not compatible with the locked Python requirement: `{1}`")]
8285
LockedPythonIncompatibility(Version, RequiresPython),
8386

0 commit comments

Comments
 (0)