Repository navigation
Expand file tree
/
Copy pathraise.rs
More file actions
61 lines (53 loc) · 2.09 KB
/
Copy pathraise.rs
File metadata and controls
61 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::context::Context;
use super::super::{DurableEngine, Error, Result};
/// Execute a Raise task - raises an error with structured error information
pub async fn exec_raise_task(
_engine: &DurableEngine,
task_name: &str,
raise_task: &serverless_workflow_core::models::task::RaiseTaskDefinition,
_ctx: &Context,
) -> Result<serde_json::Value> {
use serverless_workflow_core::models::error::OneOfErrorDefinitionOrReference;
// Extract the error definition
let error_def = match &raise_task.raise.error {
OneOfErrorDefinitionOrReference::Error(err) => err,
OneOfErrorDefinitionOrReference::Reference(ref_name) => {
return Err(Error::Configuration {
message: format!("Error references not yet implemented: {ref_name}"),
});
}
};
// Build the error object according to the spec
let mut error_obj = serde_json::json!({
"type": error_def.type_,
"title": error_def.title,
"status": error_def.status,
});
// Add optional fields if present
if let Some(detail) = &error_def.detail {
error_obj
.as_object_mut()
.ok_or_else(|| Error::Configuration {
message: "Error object is not a valid JSON object".to_string(),
})?
.insert(
"detail".to_string(),
serde_json::Value::String(detail.clone()),
);
}
// Add the instance field - this should be the path to the task in the workflow
// The path format is /do/index/taskName
let task_path = format!("/do/0/{task_name}");
error_obj
.as_object_mut()
.ok_or_else(|| Error::Configuration {
message: "Error object is not a valid JSON object".to_string(),
})?
.insert("instance".to_string(), serde_json::Value::String(task_path));
// Serialize the error to a JSON string for the error message
let error_json = serde_json::to_string(&error_obj)?;
// Return an error with the JSON-serialized error object
Err(Error::TaskExecution {
message: error_json,
})
}