Skip to content

Commit

Permalink
feat: refine error message in dev server (#183)
Browse files Browse the repository at this point in the history
Co-authored-by: Hu Yueh-Wei <[email protected]>
  • Loading branch information
leoadonia and halajohn authored Oct 23, 2024
1 parent 844b61f commit 53e2b48
Show file tree
Hide file tree
Showing 30 changed files with 437 additions and 217 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
"**/out/*/**": true,
"**/third_party/*/**": true
},
"go.formatFlags": [
"-m",
"80",
"--shorten-comments",
"-w"
],
"go.inlayHints.constantValues": true,
"go.inlayHints.parameterNames": true,
"go.inlayHints.rangeVariableTypes": true,
Expand Down
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 @@ -139,7 +144,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
9 changes: 3 additions & 6 deletions core/src/ten_manager/src/dev_server/graphs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
use ten_rust::pkg_info::pkg_type::PkgType;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct RespGraph {
pub struct RespGraph {
name: String,
auto_start: bool,
}
Expand All @@ -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
Loading

0 comments on commit 53e2b48

Please sign in to comment.