Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refine error message in dev server #183

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/src/ten_manager/src/cmd/cmd_check/cmd_check_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ fn get_existed_pkgs_of_all_apps(

for app in &command.app {
let app_path = path::Path::new(app);
let app_property = parse_property_in_folder(app_path)?;
let app_existed_pkgs = get_all_existed_pkgs_info_of_app(app_path)?;

let app_uri = app_property.get_app_uri();
let app_property = parse_property_in_folder(app_path)?;
let app_uri = if let Some(property) = app_property {
property.get_app_uri()
} else {
localhost()
};

if !single_app && app_uri.as_str() == localhost() {
return Err(anyhow::anyhow!(
"The app uri should be some string other than 'localhost' when
Expand Down Expand Up @@ -138,7 +143,12 @@ fn get_graphs_to_be_checked(command: &CheckGraphCommand) -> Result<Vec<Graph>> {
} else {
let first_app_path = path::Path::new(&command.app[0]);
let first_app_property = parse_property_in_folder(first_app_path)?;
if first_app_property.is_none() {
return Err(anyhow::anyhow!("The property.json is not found in the first app, which is required to retrieve the predefined graphs."));
}

let predefined_graphs = first_app_property
.unwrap()
._ten
.and_then(|p| p.predefined_graphs)
.ok_or_else(|| {
Expand Down
7 changes: 2 additions & 5 deletions core/src/ten_manager/src/dev_server/addons/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ pub async fn get_extension_addons(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand Down
7 changes: 2 additions & 5 deletions core/src/ten_manager/src/dev_server/graphs/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ pub async fn get_graph_connections(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand Down
7 changes: 2 additions & 5 deletions core/src/ten_manager/src/dev_server/graphs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ pub async fn get_graphs(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return Ok(HttpResponse::NotFound().json(error_response));
}

Expand Down
39 changes: 18 additions & 21 deletions core/src/ten_manager/src/dev_server/graphs/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,8 @@ pub async fn get_graph_nodes(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand All @@ -227,14 +224,14 @@ pub async fn get_graph_nodes(
match get_extension_nodes_in_graph(&graph_name, all_pkgs) {
Ok(exts) => exts,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Error fetching runtime extensions for graph '{}': {}",
graph_name, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Error fetching runtime extensions for graph '{}'",
graph_name
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}
};
Expand All @@ -243,14 +240,14 @@ pub async fn get_graph_nodes(
for extension in &extensions {
let pkg_info = get_pkg_info_for_extension(extension, all_pkgs);
if let Err(err) = pkg_info {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Error fetching runtime extensions for graph '{}': {}",
graph_name, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Error fetching runtime extensions for graph '{}'",
graph_name
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}

Expand Down
16 changes: 6 additions & 10 deletions core/src/ten_manager/src/dev_server/graphs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ pub async fn update_graph(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand All @@ -64,11 +61,10 @@ pub async fn update_graph(
) {
Ok(graph) => graph,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Invalid input data: {}", err),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
"Invalid input data:",
);
return HttpResponse::NotFound().json(error_response);
}
};
Expand Down
19 changes: 6 additions & 13 deletions core/src/ten_manager/src/dev_server/manifest/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ pub async fn check_manifest(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand All @@ -55,14 +52,10 @@ pub async fn check_manifest(
HttpResponse::Ok().json(response)
}
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Failed to check manifest: {}",
err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
"Failed to check manifest:",
);
HttpResponse::NotFound().json(error_response)
}
},
Expand Down
17 changes: 6 additions & 11 deletions core/src/ten_manager/src/dev_server/manifest/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ pub async fn dump_manifest(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand All @@ -59,12 +56,10 @@ pub async fn dump_manifest(
if let Err(err) =
dump_manifest_str_to_file(&new_manifest_str, manifest_file_path)
{
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Failed to dump new manifest content to manifest file: {}",
err),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
"Failed to dump new manifest content to manifest file:",
);
return HttpResponse::NotFound().json(error_response);
}

Expand Down
117 changes: 56 additions & 61 deletions core/src/ten_manager/src/dev_server/messages/compatible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ pub async fn get_compatible_messages(

// Fetch all packages if not already done.
if let Err(err) = get_all_pkgs(&mut state) {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!("Error fetching packages: {}", err),
error: None,
};
let error_response =
ErrorResponse::from_error(&err, "Error fetching packages:");
return HttpResponse::NotFound().json(error_response);
}

Expand All @@ -107,14 +104,14 @@ pub async fn get_compatible_messages(
match get_extension_nodes_in_graph(&input.graph, all_pkgs) {
Ok(exts) => exts,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Error fetching runtime extensions for graph: {}: {}",
input.graph, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Error fetching runtime extensions for graph '{}'",
input.graph
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}
};
Expand All @@ -127,29 +124,27 @@ pub async fn get_compatible_messages(
) {
Ok(ext) => ext,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Failed to find the extension: {}: {}",
input.extension, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Failed to find the extension: {}",
input.extension
)
.as_str(),
);

return HttpResponse::NotFound().json(error_response);
}
};

let msg_ty = match MsgType::from_str(&input.msg_type) {
Ok(msg_ty) => msg_ty,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Unsupported message type: {}: {}",
input.msg_type, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!("Unsupported message type: {}", input.msg_type)
.as_str(),
);
return HttpResponse::InternalServerError()
.json(error_response);
}
Expand All @@ -158,14 +153,14 @@ pub async fn get_compatible_messages(
let msg_dir = match MsgDirection::from_str(&input.msg_direction) {
Ok(msg_dir) => msg_dir,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Unsupported message direction: {}: {}",
input.msg_direction, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Unsupported message direction: {}",
input.msg_direction
)
.as_str(),
);
return HttpResponse::InternalServerError()
.json(error_response);
}
Expand All @@ -176,14 +171,14 @@ pub async fn get_compatible_messages(

let pkg_info = get_pkg_info_for_extension(extension, all_pkgs);
if let Err(err) = pkg_info {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Error fetching runtime extensions for graph: {}: {}",
input.graph, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Error fetching runtime extensions for graph '{}'",
input.graph
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}

Expand Down Expand Up @@ -212,14 +207,14 @@ pub async fn get_compatible_messages(
) {
Ok(results) => results,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Failed to find compatible cmd/{}: {}",
input.msg_name, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Failed to find compatible cmd/{}:",
input.msg_name
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}
};
Expand Down Expand Up @@ -268,14 +263,14 @@ pub async fn get_compatible_messages(
) {
Ok(results) => results,
Err(err) => {
let error_response = ErrorResponse {
status: Status::Fail,
message: format!(
"Failed to find compatible cmd/{}: {}",
input.msg_name, err
),
error: None,
};
let error_response = ErrorResponse::from_error(
&err,
format!(
"Failed to find compatible cmd/{}:",
input.msg_name
)
.as_str(),
);
return HttpResponse::NotFound().json(error_response);
}
};
Expand Down
Loading
Loading