Skip to content

Commit c4bd329

Browse files
committed
fix(toolchain): fix creating route failing silently
1 parent 0fe4979 commit c4bd329

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

packages/common/formatted-error/errors/route/invalid_name_id.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description_basic = "The route name_id format is invalid."
55
http_status = 400
66
---
77

8-
# invalid_name_id
8+
# Invalid Name ID
99

1010
The name_id provided for the route is invalid. Route name_ids must be lowercase alphanumeric or dashes without repeating double dashes, and are limited to 16 characters.
1111

@@ -22,4 +22,4 @@ Make sure your name_id:
2222
### Examples
2323

2424
Invalid: `UPPERCASE-route`, `route--name`, `-route-name`, `route-name-`
25-
Valid: `my-route`, `route-123`, `api-v2`
25+
Valid: `my-route`, `route-123`, `api-v2`

packages/toolchain/cli/src/util/deploy.rs

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -394,55 +394,41 @@ async fn create_function_route(
394394
route_tags: &HashMap<String, String>,
395395
default_hostname: &str,
396396
) -> Result<()> {
397-
// Get route_subpaths and strip_prefix from config
398397
let default_route_subpaths = function.route_subpaths.unwrap_or(true);
399398
let default_strip_prefix = function.strip_prefix.unwrap_or(true);
400399

401-
// Loop until route creation succeeds
402-
let mut route_created = false;
403-
while !route_created {
404-
let hostname = default_hostname.to_string();
405-
let path = function.path();
406-
let route_subpaths = default_route_subpaths;
407-
let strip_prefix = default_strip_prefix;
408-
409-
// Prepare route body
410-
let update_route_body = models::RoutesUpdateRouteBody {
411-
hostname,
412-
path,
413-
route_subpaths,
414-
strip_prefix,
415-
target: Box::new(models::RoutesRouteTarget {
416-
actors: Some(Box::new(models::RoutesRouteTargetActors {
417-
selector_tags: route_tags.clone(),
418-
})),
419-
}),
420-
};
421-
422-
// Create/update route
423-
let result = apis::routes_api::routes_update(
424-
&ctx.openapi_config_cloud,
425-
&fn_name,
426-
update_route_body.clone(),
427-
Some(&ctx.project.name_id.to_string()),
428-
Some(&environment.slug),
429-
)
430-
.await;
431-
432-
match result {
433-
Result::Ok(_) => {
434-
println!(
435-
"Successfully created route: {}{}",
436-
update_route_body.hostname, update_route_body.path
437-
);
438-
route_created = true;
439-
}
440-
Err(err) => {
441-
eprintln!("Failed to create route: {}", err);
442-
break;
443-
}
444-
}
445-
}
400+
let hostname = default_hostname.to_string();
401+
let path = function.path();
402+
let route_subpaths = default_route_subpaths;
403+
let strip_prefix = default_strip_prefix;
404+
405+
// Prepare route body
406+
let update_route_body = models::RoutesUpdateRouteBody {
407+
hostname,
408+
path,
409+
route_subpaths,
410+
strip_prefix,
411+
target: Box::new(models::RoutesRouteTarget {
412+
actors: Some(Box::new(models::RoutesRouteTargetActors {
413+
selector_tags: route_tags.clone(),
414+
})),
415+
}),
416+
};
417+
418+
// Create/update route
419+
apis::routes_api::routes_update(
420+
&ctx.openapi_config_cloud,
421+
&fn_name,
422+
update_route_body.clone(),
423+
Some(&ctx.project.name_id.to_string()),
424+
Some(&environment.slug),
425+
)
426+
.await?;
427+
428+
println!(
429+
"Successfully created route: {}{}",
430+
update_route_body.hostname, update_route_body.path
431+
);
446432

447433
Ok(())
448434
}

0 commit comments

Comments
 (0)