improve error message when the CLI and dioxus versions don't match (#2683)
This commit is contained in:
1 parent
ea3d88c1dd
commit
841b447d2a
6 files changed
+45
-7
No files matched your search
@@ -0,0 +1,2 @@
|
||||
// The file has been placed there by the build script.
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
@@ -11,19 +11,23 @@ pub use bundle::*;
|
||||
mod serve;
|
||||
pub use serve::*;
|
||||
|
||||
mod build_info;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
use crate::DioxusConfig;
|
||||
|
||||
pub(crate) const DIOXUS_CLI_VERSION: &str = "DIOXUS_CLI_VERSION";
|
||||
pub(crate) const CONFIG_ENV: &str = "DIOXUS_CONFIG";
|
||||
pub(crate) const CONFIG_BASE_PATH_ENV: &str = "DIOXUS_CONFIG_BASE_PATH";
|
||||
|
||||
pub fn save_config(config: &DioxusConfig) -> CrateConfigDropGuard {
|
||||
pub fn save_config(config: &DioxusConfig, cli_version: &str) -> CrateConfigDropGuard {
|
||||
std::env::set_var(CONFIG_ENV, serde_json::to_string(config).unwrap());
|
||||
std::env::set_var(
|
||||
CONFIG_BASE_PATH_ENV,
|
||||
config.web.app.base_path.clone().unwrap_or_default(),
|
||||
);
|
||||
std::env::set_var(DIOXUS_CLI_VERSION, cli_version);
|
||||
CrateConfigDropGuard
|
||||
}
|
||||
|
||||
@@ -34,6 +38,7 @@ pub mod __private {
|
||||
fn drop(&mut self) {
|
||||
std::env::remove_var(CONFIG_ENV);
|
||||
std::env::remove_var(CONFIG_BASE_PATH_ENV);
|
||||
std::env::remove_var(DIOXUS_CLI_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,11 +66,28 @@ pub static CURRENT_CONFIG: once_cell::sync::Lazy<
|
||||
Result<crate::config::DioxusConfig, DioxusCLINotUsed>,
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
CURRENT_CONFIG_JSON
|
||||
.and_then(|config| serde_json::from_str(config).ok())
|
||||
.ok_or_else(|| {
|
||||
tracing::warn!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
|
||||
DioxusCLINotUsed
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
tracing::warn!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
|
||||
DioxusCLINotUsed
|
||||
}).and_then(
|
||||
|config|
|
||||
match serde_json::from_str(config) {
|
||||
Ok(config) => Ok(config),
|
||||
Err(err) => {
|
||||
let mut cli_version = crate::build_info::PKG_VERSION.to_string();
|
||||
|
||||
if let Some(hash) = crate::build_info::GIT_COMMIT_HASH_SHORT {
|
||||
let hash = &hash.trim_start_matches('g')[..4];
|
||||
cli_version.push_str(&format!("-{hash}"));
|
||||
}
|
||||
|
||||
let dioxus_version = std::option_env!("DIOXUS_CLI_VERSION").unwrap_or("unknown");
|
||||
|
||||
tracing::warn!("Failed to parse the CLI config file. This is likely caused by a mismatch between the version of the CLI and the dioxus version.\nCLI version: {cli_version}\nDioxus version: {dioxus_version}\nSerialization error: {err}");
|
||||
Err(DioxusCLINotUsed)
|
||||
}
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
#[cfg(feature = "read-config")]
|
||||
|
||||
Reference in new issue
Block a user