长度与范围越界改用独立校验原因
- TripoValidationReason 新增 OutOfRange,与「参数组合互斥」不再共用 InvalidCombination - prompt 超 1024 字符、negative_prompt 超 255 字符改报 OutOfRange - face_limit 越界属同一类范围错误,一并改报 OutOfRange,调用方可按原因分流
This commit is contained in:
@@ -62,6 +62,8 @@ impl fmt::Display for TripoField {
|
||||
pub enum TripoValidationReason {
|
||||
Required,
|
||||
InvalidCombination,
|
||||
/// 取值超出该字段允许的长度或范围,与「参数组合互斥」区分开。
|
||||
OutOfRange,
|
||||
}
|
||||
|
||||
impl fmt::Display for TripoValidationReason {
|
||||
@@ -69,6 +71,7 @@ impl fmt::Display for TripoValidationReason {
|
||||
f.write_str(match self {
|
||||
Self::Required => "required",
|
||||
Self::InvalidCombination => "invalid combination",
|
||||
Self::OutOfRange => "out of range",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ pub(crate) fn validate_generation_options(
|
||||
if face_limit < minimum || face_limit > maximum {
|
||||
return Err(invalid(
|
||||
Some(TripoField::FaceLimit),
|
||||
TripoValidationReason::InvalidCombination,
|
||||
TripoValidationReason::OutOfRange,
|
||||
&format!(
|
||||
"face_limit must be between {minimum} and {maximum} for the selected model and options"
|
||||
),
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn validate_text_to_model_params(params: &Model3dTextToModelParams) -> Resul
|
||||
if params.prompt.chars().count() > 1024 {
|
||||
return Err(TripoError::InvalidParameters {
|
||||
field: Some(TripoField::Prompt),
|
||||
reason: TripoValidationReason::InvalidCombination,
|
||||
reason: TripoValidationReason::OutOfRange,
|
||||
message: "prompt must not exceed 1024 characters".into(),
|
||||
});
|
||||
}
|
||||
@@ -27,7 +27,7 @@ pub fn validate_text_to_model_params(params: &Model3dTextToModelParams) -> Resul
|
||||
{
|
||||
return Err(TripoError::InvalidParameters {
|
||||
field: Some(TripoField::NegativePrompt),
|
||||
reason: TripoValidationReason::InvalidCombination,
|
||||
reason: TripoValidationReason::OutOfRange,
|
||||
message: "negative_prompt must not exceed 255 characters".into(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user