Skip to content

fix: silent fallback to default on any server_config.yml error#43

Open
YuevUwU wants to merge 2 commits intoTeamFlos:mainfrom
YuevUwU:server-monitor-config-error-handling
Open

fix: silent fallback to default on any server_config.yml error#43
YuevUwU wants to merge 2 commits intoTeamFlos:mainfrom
YuevUwU:server-monitor-config-error-handling

Conversation

@YuevUwU
Copy link
Copy Markdown
Contributor

@YuevUwU YuevUwU commented Mar 27, 2026

Changes

  • Use default if server_config.yml is not found
    with warn log and yaml form of default (as example for users)
    2026-03-27T16:01:57.614117Z  WARN phira_mp_server::server: server_config.yml is not found.
    Fallback to default config:
    ```yaml
    monitors:
    - 2
    ```
    2026-03-28T03:37:50.922670Z  INFO phira_mp_server::server: User IDs allowed to monitor matches: [2]
  • Terminate if raised other io::Error or serde_yaml::Error
    Error: Failed to parse server_config.yml
    
    Caused by:
        Is a directory (os error 21)
    
    Error: Failed to parse server_config.yml
    
    Caused by:
        missing field `monitors`
    
    Error: Failed to parse server_config.yml
    
    Caused by:
        monitors[0]: invalid type: string "41321", expected i32 at line 1 column 12
    
  • Log current monitors config
     2026-03-28T03:37:41.402080Z  INFO phira_mp_server::server: User IDs allowed to monitor matches: [41321]
    
  • TcpListener -> Server is now TryFrom
  • Extract "server_config.yml" to a const string

chore: log config.monitors with info!

Past Problem

let config: ServerConfig = File::open("server_config.yml")  // Result<ServerConfig, io::Error>
    .ok()
    .and_then(|f| serde_yaml::from_reader(f).ok())  // 
    .unwrap_or_default();  // Suppress all error.
// User don't know if it's okay or failed

It's now no longer suppress errors, and users can be aware of their current configuration. (just like phira-monitor)
Mivik can still use without server_config.yml file in phira-mp-server::server::CONFIG_PATH.
But other error is now considered as hard error.

Extra Consideration (NOT in this PR)

In my environment, the default max log level is error.
This patch could be considered to "RUST_LOG=warn by default", and still check RUST_LOG first.
This is better than simply writing RUST_LOG=info in the README.md.
(Edge Case: If someone set RUST_LOG as invalid string, it still apply and suppress, and won't use warn by default.)

diff --git a/phira-mp-server/src/main.rs b/phira-mp-server/src/main.rs
index d50916f..80bec15 100644
--- a/phira-mp-server/src/main.rs
+++ b/phira-mp-server/src/main.rs
@@ -65,9 +65,11 @@ pub fn init_log(file: &str) -> Result<WorkerGuard> {
                 .with_filter(LevelFilter::DEBUG),
         )
         .with(
-            fmt::layer()
-                .with_writer(std::io::stdout)
-                .with_filter(EnvFilter::from_default_env()),
+            fmt::layer().with_writer(std::io::stdout).with_filter(
+                EnvFilter::builder()
+                    .with_default_directive(LevelFilter::WARN.into())
+                    .from_env_lossy(),
+            ),
         )
         .with(
             filter::Targets::new()

- Use default if server_config.yml is not found
  with warn log and yaml form of default (as example for users)
- Stop if raised other io::Error or serde_yaml::Error
- TcpListener -> Server is now TryFrom
@YuevUwU YuevUwU force-pushed the server-monitor-config-error-handling branch from 485feb9 to 24b3354 Compare March 28, 2026 03:50
@YuevUwU YuevUwU force-pushed the server-monitor-config-error-handling branch from 24b3354 to d180b14 Compare March 28, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant