Skip to content

Commit 287a8e8

Browse files
authored
cli: Avoid empty error message (#4230)
If the `dev` command encounters an HTTP error when fetching module logs, it relies on the server to also send some error description in the response body. That isn't always the case, so default to the status code + canonical reason phrase # Expected complexity level and risk 1 # Testing n/a
1 parent 7b0ec8a commit 287a8e8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • crates/cli/src/subcommands

crates/cli/src/subcommands/dev.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn cli() -> Command {
6161
.help("The path to the module bindings directory relative to the project directory, defaults to `<project-path>/src/module_bindings`"),
6262
)
6363
// NOTE: All server templates must have their server code in `spacetimedb/` directory
64-
// This is not a requirement in general, but is a requirement for all templates
64+
// This is not a requirement in general, but is a requirement for all templates
6565
// i.e. `spacetime dev` is valid on non-templates.
6666
.arg(
6767
Arg::new("module-project-path")
@@ -620,7 +620,13 @@ async fn stream_logs(
620620

621621
let status = res.status();
622622
if status.is_client_error() || status.is_server_error() {
623-
let err = res.text().await?;
623+
let mut err = res.text().await?;
624+
// The server doesn't always send an error description in the response
625+
// body (maybe it should), so default to status code + canonical reason
626+
// phrase (e.g. "502 Bad Gateway").
627+
if err.is_empty() {
628+
err = format!("{status}");
629+
}
624630
anyhow::bail!(err)
625631
}
626632

0 commit comments

Comments
 (0)