riker-rs / riker

Easily build efficient, highly concurrent and resilient applications. An Actor Framework for Rust.
https://riker.rs
MIT License
1.02k stars 69 forks source link

default config, don't try to unwrap if the toml not found #13

Closed thedavidmeister closed 6 years ago

thedavidmeister commented 6 years ago

I'm getting this if i haven't setup the config toml:

thread 'tests::can_instantiate' panicked at 'called `Result::unwrap()` on an `Err` value: configuration file "config/riker.toml" not found', libcore/result.rs:945:5

it seems to me that default fallback config could work better than an unwrap

leenozara commented 6 years ago

@thedavidmeister This is a conscious design decision. Riker should work exactly how you have configured it, or not at all and fail to start. The Riker "philosophy" is that it's better to fail an application than let it run using an unknown configuration. It's the same for individual config parameters, if they're not provided in the file but expected in code the application should not start. This allows us to identify problems right when an application is tested during CI/CD instead of deploying the application and realizing some time after in production that it is not using the correct configuration.

Scala's Akka uses the same approach.

Your comment though highlights that in the Riker documentation configuration is not covered until after the basic examples. I guess most people run into this error if they're following the documentation, which isn't good at all.

How about I make this issue about improving the documentation? Would that work for you?

Greatly appreciate your contribution in pointing this out, thanks!

leenozara commented 6 years ago

@thedavidmeister Actually I stand corrected. In Akka it is possible to start an application without a config file. Only the individual parameters should fail if they don't exist.

Let me review this a little more. Just FYI I tend to use Akka as a reference since I'm familiar with it and it is well designed. I guess in this instance I'm not so familiar :).

thedavidmeister commented 6 years ago

yes it certainly seems like one of those things that a beginner like me would run into early, but someone more experienced wouldn't even notice

i also found it awkward that i had to symlink the config into place to support a repo with several crates in it, even for crates that did not use riker but depended on crates that did (so there was a copy of the same config in both crates).

thedavidmeister commented 6 years ago

i also haven't tested this, but the error i saw was along the lines of "file not found" not "config not found"

this would mean that i can provide all the config directly in the code but then need to ship an empty config file, which doesn't seem right even given the riker philosophy

leenozara commented 6 years ago

@thedavidmeister There's a PR config-fix that addresses your issue:

riker.toml is optional. If it is not provided then default values for the bare minimum settings are used.

Again, thanks so much for your help pointing this out and working with me to design a nice fix for beginners. If there's anything else you see that needs improving, especially from a beginner's perspective please let me know and I'll jump on it.

Let me know if this fixes your issue and we can close it. Thanks!

leenozara commented 6 years ago

@thedavidmeister

Regarding your symlinking. It's possible to override the location using an env variable:

Example:

export RIKER_CONF=/var/conf/riker/riker.toml.

This feature is already there but not documented. I'll add an issue to add this to the documentation.

leenozara commented 6 years ago

Closing this as it was merged into 0.1.5