Skip to content

Commit b08038c

Browse files
committed
feat: better error if array len >=1
1 parent e555181 commit b08038c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

router/src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,23 @@ mod prompt_serde {
277277
let value = Value::deserialize(deserializer)?;
278278
match value {
279279
Value::String(s) => Ok(s),
280-
Value::Array(arr) => arr
281-
.first()
282-
.and_then(|v| v.as_str())
283-
.map(|s| s.to_string())
284-
.ok_or_else(|| {
285-
serde::de::Error::custom("array is empty or contains non-string elements")
286-
}),
280+
Value::Array(arr) => {
281+
if arr.len() == 1 {
282+
match arr[0].as_str() {
283+
Some(s) => Ok(s.to_string()),
284+
None => Err(serde::de::Error::custom(
285+
"Array contains non-string elements",
286+
)),
287+
}
288+
} else {
289+
Err(serde::de::Error::custom(
290+
"Array contains non-string element. Expected string. In general arrays should not be used for prompts. Please use a string instead if possible.",
291+
))
292+
}
293+
}
294+
287295
_ => Err(serde::de::Error::custom(
288-
"expected a string or an array of strings",
296+
"Expected a string or an array of strings",
289297
)),
290298
}
291299
}

0 commit comments

Comments
 (0)