Skip to main content

cuprated/
constants.rs

1//! General constants used throughout `cuprated`.
2use std::time::Duration;
3
4use const_format::formatcp;
5
6/// `cuprated`'s semantic version (`MAJOR.MINOR.PATCH`) as string.
7pub const VERSION: &str = clap::crate_version!();
8
9/// Major version number of `cuprated`.
10pub const MAJOR_VERSION: &str = env!("CARGO_PKG_VERSION_MAJOR");
11
12/// Major version number of `cuprated`.
13pub const MINOR_VERSION: &str = env!("CARGO_PKG_VERSION_MINOR");
14
15/// Patch version number of `cuprated`.
16pub const PATCH_VERSION: &str = env!("CARGO_PKG_VERSION_PATCH");
17
18/// [`VERSION`] + the build type.
19///
20/// If a debug build, the suffix is `-debug`, else it is `-release`.
21pub const VERSION_BUILD: &str = formatcp!("{VERSION}-{}", cuprate_constants::build::BUILD);
22
23/// The panic message used when cuprated encounters a critical service error.
24pub const PANIC_CRITICAL_SERVICE_ERROR: &str =
25    "A service critical to Cuprate's function returned an unexpected error.";
26
27pub const DEFAULT_CONFIG_WARNING: &str = formatcp!(
28    "WARNING: no config file found, using default config.\
29    \nThe default config may not be optimal for your setup, see the user book here: https://user.cuprate.org/.\
30    \nPausing startup for {} seconds. \
31    \nUse the `--skip-config-warning` arg to skip this delay if you really want to use the default.",
32    DEFAULT_CONFIG_STARTUP_DELAY.as_secs()
33);
34
35pub const DEFAULT_CONFIG_STARTUP_DELAY: Duration = Duration::from_secs(15);
36
37/// Corrupt database error message.
38///
39/// The error message shown to end-users in panic
40/// messages if we think the database is corrupted.
41///
42/// This is meant to be user-friendly.
43pub const DATABASE_CORRUPT_MSG: &str = r"`cuprated` has encountered a fatal error. The database may be corrupted.
44
45If `cuprated` continues to crash with the current database,
46you may have to delete the database file and re-sync from scratch.
47
48See <https://user.cuprate.org/resources/disk.html>
49for more information on where database files are.
50
51If this happens frequently, consider using the `Safe` sync mode.";
52
53#[cfg(test)]
54mod test {
55    use super::*;
56    use crate::config::Config;
57
58    #[test]
59    fn version() {
60        let semantic_version = format!("{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}");
61        assert_eq!(VERSION, VERSION);
62        assert_eq!(VERSION, "0.1.0-preview");
63    }
64
65    #[test]
66    fn version_build() {
67        if cfg!(debug_assertions) {
68            assert_eq!(VERSION_BUILD, "0.1.0-preview-debug");
69        } else {
70            assert_eq!(VERSION_BUILD, "0.1.0-preview-release");
71        }
72    }
73}