Files
dioxus/packages/cli/src/error.rs
T
Brian Donovan 6d154b5072 Minor Proxy Improvements (#1289)
* fix(serve): provide a clear error with pathless proxy URLs

Without this, `dx serve` panics with this message:

```
Paths must start with a `/`. Use "/" for
 root routes
 ```

 That's not very clear. Instead, we can detect this situation and provide a better error message:

```
Error: 🚫 Serving project failed: Failed to establish proxy: Proxy backend URL must have a non-empty path, e.g. http://localhost:8080/api instead of http://localhost:8080
```

* docs(config): correct format for `web.proxy`
2023-08-04 13:44:56 -05:00

84 lines
1.8 KiB
Rust

use thiserror::Error as ThisError;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(ThisError, Debug)]
pub enum Error {
/// Used when errors need to propogate but are too unique to be typed
#[error("{0}")]
Unique(String),
#[error("I/O Error: {0}")]
IO(#[from] std::io::Error),
#[error("Format Error: {0}")]
FormatError(#[from] std::fmt::Error),
#[error("Format failed: {0}")]
ParseError(String),
#[error("Runtime Error: {0}")]
RuntimeError(String),
#[error("Failed to write error")]
FailedToWrite,
#[error("Build Failed: {0}")]
BuildFailed(String),
#[error("Cargo Error: {0}")]
CargoError(String),
#[error("{0}")]
CustomError(String),
#[error("Invalid proxy URL: {0}")]
InvalidProxy(#[from] hyper::http::uri::InvalidUri),
#[error("Failed to establish proxy: {0}")]
ProxySetupError(String),
#[error("Error proxying request: {0}")]
ProxyRequestError(hyper::Error),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Error::Unique(s.to_string())
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Error::Unique(s)
}
}
impl From<html_parser::Error> for Error {
fn from(e: html_parser::Error) -> Self {
Self::ParseError(e.to_string())
}
}
impl From<hyper::Error> for Error {
fn from(e: hyper::Error) -> Self {
Self::RuntimeError(e.to_string())
}
}
#[macro_export]
macro_rules! custom_error {
($msg:literal $(,)?) => {
Err(Error::CustomError(format!($msg)))
};
($err:expr $(,)?) => {
Err(Error::from($err))
};
($fmt:expr, $($arg:tt)*) => {
Err(Error::CustomError(format!($fmt, $($arg)*)))
};
}