62 lines
2.3 KiB
Rust
62 lines
2.3 KiB
Rust
use std::{error::Error, fmt};
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum AiTaskFieldError {
|
|
MissingTaskId,
|
|
MissingOwnerUserId,
|
|
MissingRequestLabel,
|
|
MissingSourceModule,
|
|
MissingStageBlueprints,
|
|
DuplicateStageBlueprint,
|
|
MissingReferenceId,
|
|
MissingChunkText,
|
|
InvalidSequence,
|
|
MissingFailureMessage,
|
|
MissingStage,
|
|
InvalidTaskState,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum AiTaskServiceError {
|
|
Field(AiTaskFieldError),
|
|
TaskAlreadyExists,
|
|
TaskNotFound,
|
|
StageNotFound,
|
|
Store(String),
|
|
}
|
|
|
|
impl fmt::Display for AiTaskFieldError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::MissingTaskId => f.write_str("ai_task.task_id 不能为空"),
|
|
Self::MissingOwnerUserId => f.write_str("ai_task.owner_user_id 不能为空"),
|
|
Self::MissingRequestLabel => f.write_str("ai_task.request_label 不能为空"),
|
|
Self::MissingSourceModule => f.write_str("ai_task.source_module 不能为空"),
|
|
Self::MissingStageBlueprints => f.write_str("ai_task.stages 至少需要一个有效阶段"),
|
|
Self::DuplicateStageBlueprint => f.write_str("ai_task.stages 不能包含重复阶段"),
|
|
Self::MissingReferenceId => f.write_str("ai_result_reference.reference_id 不能为空"),
|
|
Self::MissingChunkText => f.write_str("ai_text_chunk.delta_text 不能为空"),
|
|
Self::InvalidSequence => f.write_str("ai_text_chunk.sequence 必须大于 0"),
|
|
Self::MissingFailureMessage => f.write_str("ai_task.failure_message 不能为空"),
|
|
Self::MissingStage => f.write_str("ai_task.stage 不存在"),
|
|
Self::InvalidTaskState => f.write_str("当前 ai_task 状态不允许执行该操作"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Error for AiTaskFieldError {}
|
|
|
|
impl fmt::Display for AiTaskServiceError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::Field(error) => write!(f, "{error}"),
|
|
Self::TaskAlreadyExists => f.write_str("ai_task 已存在,不能重复创建"),
|
|
Self::TaskNotFound => f.write_str("ai_task 不存在"),
|
|
Self::StageNotFound => f.write_str("ai_task.stage 不存在"),
|
|
Self::Store(message) => f.write_str(message),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Error for AiTaskServiceError {}
|