Skip to content

Commit f019f9c

Browse files
committed
Make the error on a size field clearer
Previously, it said "no value can be found" which is a bit unclear
1 parent 969713d commit f019f9c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

nativelink-config/src/serde_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ where
237237
fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
238238
let expanded = shellexpand::env(v).map_err(de::Error::custom)?;
239239
let s = expanded.as_ref().trim();
240+
if v.is_empty() {
241+
return Err(de::Error::custom("Missing value in a size field"));
242+
}
240243
let byte_size = Byte::parse_str(s, true).map_err(de::Error::custom)?;
241244
let bytes = byte_size.as_u128();
242245
T::try_from(bytes).map_err(de::Error::custom)

nativelink-config/tests/deserialization_test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,17 @@ mod data_size_tests {
202202
r#"{"data_size": "999999999999999999999B"}"#,
203203
"the value 999999999999999999999 exceeds the valid range",
204204
),
205+
(r#"{"data_size": ""}"#, "Missing value in a size field"),
205206
];
206207

207208
for (input, expected_error) in examples {
208209
let error = serde_json5::from_str::<DataSizeEntity>(input)
209210
.unwrap_err()
210211
.to_string();
211-
assert!(error.contains(expected_error));
212+
assert!(
213+
error.contains(expected_error),
214+
"Error: {error} Expected: {expected_error}"
215+
);
212216
}
213217
}
214218
}

0 commit comments

Comments
 (0)