diff --git a/.gitignore b/.gitignore index a56d60c..9566e00 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /target/ # Editor Artifacts go here. /.vscode/ +/.zed/ # Notes can go here. /scratch/ @@ -17,4 +18,4 @@ /installer-scripts/unix/*.apk /installer-scripts/unix/*.deb /installer-scripts/unix/*.pkg.tar.zst -/installer-scripts/unix/*.rpm \ No newline at end of file +/installer-scripts/unix/*.rpm diff --git a/Cargo.lock b/Cargo.lock index 8380cee..187f121 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "addr2line" -version = "0.24.2" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" dependencies = [ "gimli", ] @@ -37,11 +37,20 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -54,9 +63,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" [[package]] name = "anstyle-parse" @@ -69,61 +78,40 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", -] - -[[package]] -name = "anyhow" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" - -[[package]] -name = "async-stream" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", + "windows-sys 0.60.2", ] [[package]] -name = "async-trait" -version = "0.1.88" +name = "arboard" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +checksum = "0348a1c054491f4bfe6ab86a7b6ab1e44e45d899005de92f58b3df180b36ddaf" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", + "clipboard-win", + "log", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "parking_lot", + "percent-encoding", + "windows-sys 0.60.2", + "wl-clipboard-rs", + "x11rb", ] [[package]] @@ -138,58 +126,11 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "axum" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" -dependencies = [ - "async-trait", - "axum-core", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower 0.5.2", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", -] - [[package]] name = "backtrace" -version = "0.3.75" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" dependencies = [ "addr2line", "cfg-if", @@ -197,7 +138,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets 0.52.6", + "windows-link 0.2.0", ] [[package]] @@ -209,12 +150,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -223,9 +158,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "block-padding" @@ -245,10 +180,9 @@ dependencies = [ "fnv", "futures", "libc", - "log 0.0.12", "mac_address", "miette", - "terminal_size", + "rm-lisa", "tokio", "tracing", "valuable", @@ -262,9 +196,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "bytemuck" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" +checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" [[package]] name = "byteorder" @@ -297,21 +231,21 @@ dependencies = [ "miette", "network-interface", "pin-project-lite", - "rand 0.9.1", + "rand", "reqwest", "scc", "sysinfo", "tempfile", - "thiserror 2.0.12", + "thiserror", "tokio", "tokio-util", - "tower 0.5.2", + "tower", "tracing", "valuable", "walkdir", "whoami", "wide", - "windows", + "windows 0.62.1", ] [[package]] @@ -323,18 +257,19 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.27" +version = "1.2.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" dependencies = [ + "find-msvc-tools", "shlex", ] [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "cfg_aliases" @@ -344,11 +279,15 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" dependencies = [ + "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", + "windows-link 0.2.0", ] [[package]] @@ -363,9 +302,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.40" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" +checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" dependencies = [ "clap_builder", "clap_derive", @@ -373,9 +312,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.40" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" +checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" dependencies = [ "anstream", "anstyle", @@ -388,14 +327,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.40" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -404,6 +343,15 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "clipboard-win" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" +dependencies = [ + "error-code", +] + [[package]] name = "colorchoice" version = "1.0.4" @@ -416,46 +364,6 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e57e3272f0190c3f1584272d613719ba5fc7df7f4942fe542e63d949cf3a649b" -[[package]] -name = "console-api" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857" -dependencies = [ - "futures-core", - "prost", - "prost-types", - "tonic", - "tracing-core", -] - -[[package]] -name = "console-subscriber" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01" -dependencies = [ - "console-api", - "crossbeam-channel", - "crossbeam-utils", - "futures-task", - "hdrhistogram", - "humantime", - "hyper-util", - "parking_lot", - "prost", - "prost-types", - "serde", - "serde_json", - "thread_local", - "tokio", - "tokio-stream", - "tonic", - "tracing", - "tracing-core", - "tracing-subscriber", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -481,30 +389,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - [[package]] name = "crypto-common" version = "0.1.6" @@ -523,8 +407,8 @@ dependencies = [ "cat-dev", "clap", "fnv", - "log 0.0.12", "miette", + "rm-lisa", "rtshark", "tokio", "tracing", @@ -532,12 +416,13 @@ dependencies = [ ] [[package]] -name = "deranged" -version = "0.4.0" +name = "dispatch2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ - "powerfmt", + "bitflags", + "objc2", ] [[package]] @@ -548,9 +433,15 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "ecb" version = "0.1.2" @@ -583,20 +474,32 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.1", ] +[[package]] +name = "error-code" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59" + [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" + [[package]] name = "findbridge" version = "0.0.12" @@ -608,14 +511,10 @@ dependencies = [ ] [[package]] -name = "flate2" -version = "1.1.2" +name = "fixedbitset" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" -dependencies = [ - "crc32fast", - "miniz_oxide", -] +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "fnv" @@ -625,9 +524,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] @@ -688,7 +587,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -740,14 +639,13 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.2.16" +name = "gethostname" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55" dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.1+wasi-snapshot-preview1", + "rustix 1.1.2", + "windows-targets 0.52.6", ] [[package]] @@ -759,58 +657,20 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.2+wasi-0.2.4", + "wasi 0.14.7+wasi-0.2.4", ] [[package]] name = "gimli" -version = "0.31.1" +version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" - -[[package]] -name = "h2" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap 2.10.0", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" [[package]] name = "hashbrown" -version = "0.15.4" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" - -[[package]] -name = "hdrhistogram" -version = "7.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" -dependencies = [ - "base64 0.21.7", - "byteorder", - "flate2", - "nom", - "num-traits", -] +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "heck" @@ -858,59 +718,34 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "humantime" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" - [[package]] name = "hyper" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +checksum = "eb3aa54a13a0dfe7fbe3a59e0c76093041720fdc77b110cc0fc260fafb4dc51e" dependencies = [ + "atomic-waker", "bytes", "futures-channel", - "futures-util", - "h2", + "futures-core", "http", "http-body", "httparse", - "httpdate", "itoa", "pin-project-lite", + "pin-utils", "smallvec", "tokio", "want", ] -[[package]] -name = "hyper-timeout" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" -dependencies = [ - "hyper", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "hyper-util" -version = "0.1.14" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc2fdfdbff08affe55bb779f33b053aa1fe5dd5b54c257343c17edfa55711bdb" +checksum = "3c6995591a8f1380fcb4ba966a252a4b29188d51d2b89e3a252f5305be65aea8" dependencies = [ - "base64 0.22.1", + "base64", "bytes", "futures-channel", "futures-core", @@ -930,6 +765,30 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core 0.62.1", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "2.0.0" @@ -1018,9 +877,9 @@ dependencies = [ [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -1039,22 +898,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.10.0" +version = "2.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" +checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" dependencies = [ "equivalent", - "hashbrown 0.15.4", + "hashbrown", ] [[package]] @@ -1069,9 +918,9 @@ dependencies = [ [[package]] name = "io-uring" -version = "0.7.8" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" dependencies = [ "bitflags", "cfg-if", @@ -1106,15 +955,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.15" @@ -1123,9 +963,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" dependencies = [ "once_cell", "wasm-bindgen", @@ -1139,15 +979,32 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.176" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" + +[[package]] +name = "libredox" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +dependencies = [ + "bitflags", + "libc", + "redox_syscall", +] [[package]] name = "linux-raw-sys" -version = "0.9.4" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "litemap" @@ -1163,7 +1020,7 @@ checksum = "656b3b27f8893f7bbf9485148ff9a65f019e3f33bd5cdc87c83cab16b3fd9ec8" dependencies = [ "libc", "neli", - "thiserror 2.0.12", + "thiserror", "windows-sys 0.59.0", ] @@ -1179,20 +1036,9 @@ dependencies = [ [[package]] name = "log" -version = "0.0.12" -dependencies = [ - "console-subscriber", - "miette", - "tracing", - "tracing-error", - "tracing-subscriber", -] - -[[package]] -name = "log" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "mac_address" @@ -1206,24 +1052,18 @@ dependencies = [ [[package]] name = "matchers" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" dependencies = [ - "regex-automata 0.1.10", + "regex-automata", ] -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - [[package]] name = "memchr" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "memoffset" @@ -1261,7 +1101,7 @@ checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1301,7 +1141,6 @@ name = "mionparamspace" version = "0.0.12" dependencies = [ "cat-dev", - "time", "tokio", ] @@ -1310,7 +1149,7 @@ name = "mionps" version = "0.0.12" dependencies = [ "cat-dev", - "time", + "chrono", "tokio", ] @@ -1322,7 +1161,7 @@ checksum = "93062a0dce6da2517ea35f301dfc88184ce18d3601ec786a727a87bf535deca9" dependencies = [ "byteorder", "libc", - "log 0.4.27", + "log", "neli-proc-macros", ] @@ -1341,13 +1180,13 @@ dependencies = [ [[package]] name = "network-interface" -version = "2.0.1" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3329f515506e4a2de3aa6e07027a6758e22e0f0e8eaf64fa47261cec2282602" +checksum = "07709a6d4eba90ab10ec170a0530b3aafc81cb8a2d380e4423ae41fc55fe5745" dependencies = [ "cc", "libc", - "thiserror 1.0.69", + "thiserror", "winapi", ] @@ -1376,20 +1215,13 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.46.0" +version = "0.50.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" dependencies = [ - "overload", - "winapi", + "windows-sys 0.52.0", ] -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - [[package]] name = "num-traits" version = "0.2.19" @@ -1399,6 +1231,27 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561f357ba7f3a2a61563a186a163d0a3a5247e1089524a3981d49adb775078bc" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-app-kit" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc" +dependencies = [ + "bitflags", + "objc2", + "objc2-core-graphics", + "objc2-foundation", +] + [[package]] name = "objc2-core-foundation" version = "0.3.1" @@ -1406,6 +1259,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" dependencies = [ "bitflags", + "dispatch2", + "objc2", +] + +[[package]] +name = "objc2-core-graphics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989c6c68c13021b5c2d6b71456ebb0f9dc78d752e86a98da7c716f4f9470f5a4" +dependencies = [ + "bitflags", + "dispatch2", + "objc2", + "objc2-core-foundation", + "objc2-io-surface", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" +dependencies = [ + "bitflags", + "objc2", + "objc2-core-foundation", ] [[package]] @@ -1418,11 +1303,22 @@ dependencies = [ "objc2-core-foundation", ] +[[package]] +name = "objc2-io-surface" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7282e9ac92529fa3457ce90ebb15f4ecbc383e8338060960760fa2cf75420c3c" +dependencies = [ + "bitflags", + "objc2", + "objc2-core-foundation", +] + [[package]] name = "object" -version = "0.36.7" +version = "0.37.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" dependencies = [ "memchr", ] @@ -1440,16 +1336,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] -name = "overload" -version = "0.1.1" +name = "os_pipe" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +checksum = "db335f4760b14ead6290116f2427bf33a14d4f0617d49f78a246de10c1831224" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] [[package]] name = "owo-colors" -version = "4.2.2" +version = "4.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" +checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" [[package]] name = "parking_lot" @@ -1484,28 +1384,18 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pin-project" -version = "1.1.10" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" -dependencies = [ - "pin-project-internal", -] +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] -name = "pin-project-internal" -version = "1.1.10" +name = "petgraph" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", + "fixedbitset", + "indexmap", ] [[package]] @@ -1520,21 +1410,21 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "potential_utf" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" dependencies = [ "zerovec", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -1546,45 +1436,13 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn 2.0.104", -] - -[[package]] -name = "prost-types" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" -dependencies = [ - "prost", -] - [[package]] name = "quick-xml" version = "0.37.5" @@ -1596,9 +1454,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] @@ -1611,33 +1469,12 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" -version = "0.8.5" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ - "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" -dependencies = [ - "rand_chacha 0.9.0", - "rand_core 0.9.3", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", + "rand_chacha", + "rand_core", ] [[package]] @@ -1647,16 +1484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.3", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.16", + "rand_core", ] [[package]] @@ -1665,69 +1493,54 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.3", + "getrandom", ] [[package]] name = "redox_syscall" -version = "0.5.13" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.11.1" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "8b5288124840bee7b386bc413c487869b360b2b4ec421ea56425128692f2a82c" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.9", - "regex-syntax 0.8.5", + "regex-automata", + "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", -] - -[[package]] -name = "regex-automata" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "833eb9ce86d40ef33cb1306d8accf7bc8ec2bfea4355cbdebb3df68b40925cad" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" [[package]] name = "reqwest" -version = "0.12.22" +version = "0.12.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" +checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb" dependencies = [ - "base64 0.22.1", + "base64", "bytes", "encoding_rs", "futures-core", @@ -1737,7 +1550,7 @@ dependencies = [ "hyper", "hyper-util", "js-sys", - "log 0.4.27", + "log", "mime", "percent-encoding", "pin-project-lite", @@ -1746,7 +1559,7 @@ dependencies = [ "serde_urlencoded", "sync_wrapper", "tokio", - "tower 0.5.2", + "tower", "tower-http", "tower-service", "url", @@ -1755,6 +1568,30 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rm-lisa" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42676efe2b5762a4cb6346429e74d327b33d34088c740e9778dabd1a76a0084" +dependencies = [ + "arboard", + "chrono", + "fnv", + "libc", + "owo-colors", + "parking_lot", + "regex", + "serde_json", + "thiserror", + "tracing", + "tracing-subscriber", + "unicode-width 0.2.1", + "valuable", + "valuable-serde", + "widestring", + "windows 0.62.1", +] + [[package]] name = "rtshark" version = "3.2.0" @@ -1768,28 +1605,41 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustix" -version = "1.0.7" +version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ "bitflags", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.15", "windows-sys 0.59.0", ] +[[package]] +name = "rustix" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys 0.11.0", + "windows-sys 0.61.1", +] + [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" @@ -1797,6 +1647,12 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +[[package]] +name = "saa" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "540e257511935edc5f7fbe3c472ce4f642d43f0df4333fe996dfdf0b96862c72" + [[package]] name = "safe_arch" version = "0.7.4" @@ -1817,10 +1673,11 @@ dependencies = [ [[package]] name = "scc" -version = "2.3.4" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22b2d775fb28f245817589471dd49c5edf64237f4a19d10ce9a92ff4651a27f4" +checksum = "93ef1d3a981ec33b3924730d96a607a8defd69a9660895cce9f5155fe7f1d7c0" dependencies = [ + "saa", "sdd", ] @@ -1832,46 +1689,57 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sdd" -version = "3.0.8" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584e070911c7017da6cb2eb0788d09f43d789029b5877d3e5ecc8acf86ceee21" +checksum = "289309f6b5c6a090488f188a75e98d96007e763b892018de92b5889eb09a03f4" [[package]] name = "semver" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" dependencies = [ "itoa", "memchr", "ryu", "serde", + "serde_core", ] [[package]] @@ -1911,18 +1779,18 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" dependencies = [ "libc", ] [[package]] name = "slab" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" [[package]] name = "smallvec" @@ -1932,12 +1800,12 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.5.10" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1986,9 +1854,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -2012,19 +1880,19 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "sysinfo" -version = "0.35.2" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3ffa3e4ff2b324a57f7aeb3c349656c7b127c3c189520251a648102a92496e" +checksum = "3bddd368fda2f82ead69c03d46d351987cfa0c2a57abfa37a017f3aa3e9bf69a" dependencies = [ "libc", "objc2-core-foundation", "objc2-io-kit", - "windows", + "windows 0.61.3", ] [[package]] @@ -2050,25 +1918,25 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.20.0" +version = "3.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", - "getrandom 0.3.3", + "getrandom", "once_cell", - "rustix", - "windows-sys 0.59.0", + "rustix 1.1.2", + "windows-sys 0.61.1", ] [[package]] name = "terminal_size" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" dependencies = [ - "rustix", - "windows-sys 0.59.0", + "rustix 1.1.2", + "windows-sys 0.60.2", ] [[package]] @@ -2083,42 +1951,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - -[[package]] -name = "thiserror" -version = "2.0.12" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ - "thiserror-impl 2.0.12", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", + "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2130,25 +1978,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "time" -version = "0.3.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" -dependencies = [ - "deranged", - "num-conv", - "powerfmt", - "serde", - "time-core", -] - -[[package]] -name = "time-core" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" - [[package]] name = "tinystr" version = "0.8.1" @@ -2161,9 +1990,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.46.0" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1140bb80481756a8cbe10541f37433b459c5aa1e727b4c020fbfebdc25bf3ec4" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", @@ -2177,7 +2006,7 @@ dependencies = [ "socket2", "tokio-macros", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2188,25 +2017,14 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", -] - -[[package]] -name = "tokio-stream" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", + "syn 2.0.106", ] [[package]] name = "tokio-util" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" dependencies = [ "bytes", "futures-core", @@ -2215,56 +2033,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tonic" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" -dependencies = [ - "async-stream", - "async-trait", - "axum", - "base64 0.22.1", - "bytes", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-timeout", - "hyper-util", - "percent-encoding", - "pin-project", - "prost", - "socket2", - "tokio", - "tokio-stream", - "tower 0.4.13", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "indexmap 1.9.3", - "pin-project", - "pin-project-lite", - "rand 0.8.5", - "slab", - "tokio", - "tokio-util", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "tower" version = "0.5.2" @@ -2293,7 +2061,7 @@ dependencies = [ "http-body", "iri-string", "pin-project-lite", - "tower 0.5.2", + "tower", "tower-layer", "tower-service", ] @@ -2329,7 +2097,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2342,23 +2110,13 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-error" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" -dependencies = [ - "tracing", - "tracing-subscriber", -] - [[package]] name = "tracing-log" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ - "log 0.4.27", + "log", "once_cell", "tracing-core", ] @@ -2377,15 +2135,14 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5" dependencies = [ "matchers", "nu-ansi-term", "once_cell", - "parking_lot", - "regex", + "regex-automata", "serde", "serde_json", "sharded-slab", @@ -2399,6 +2156,18 @@ dependencies = [ "valuable-serde", ] +[[package]] +name = "tree_magic_mini" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f943391d896cdfe8eec03a04d7110332d445be7df856db382dd96a730667562c" +dependencies = [ + "memchr", + "nom", + "once_cell", + "petgraph", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -2419,9 +2188,9 @@ checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "unicode-linebreak" @@ -2443,13 +2212,14 @@ checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" [[package]] name = "url" -version = "2.5.4" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -2481,7 +2251,7 @@ checksum = "4e3a32a9bcc0f6c6ccfd5b27bcf298c58e753bcc9eeff268157a303393183a6d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2527,11 +2297,20 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -2542,35 +2321,36 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" dependencies = [ "bumpalo", - "log 0.4.27", + "log", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.50" +version = "0.4.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" dependencies = [ "cfg-if", "js-sys", @@ -2581,9 +2361,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2591,31 +2371,101 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" dependencies = [ "unicode-ident", ] +[[package]] +name = "wayland-backend" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673a33c33048a5ade91a6b139580fa174e19fb0d23f396dca9fa15f2e1e49b35" +dependencies = [ + "cc", + "downcast-rs", + "rustix 1.1.2", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c66a47e840dc20793f2264eb4b3e4ecb4b75d91c0dd4af04b456128e0bdd449d" +dependencies = [ + "bitflags", + "rustix 1.1.2", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efa790ed75fbfd71283bd2521a1cfdc022aabcc28bdcff00851f9e4ae88d9901" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd94963ed43cf9938a090ca4f7da58eb55325ec8200c3848963e98dc25b78ec" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34949b42822155826b41db8e5d0c1be3a2bd296c747577a43a3e6daefc296142" +dependencies = [ + "pkg-config", +] + [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" dependencies = [ "js-sys", "wasm-bindgen", @@ -2623,11 +2473,11 @@ dependencies = [ [[package]] name = "whoami" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6994d13118ab492c3c80c1f81928718159254c53c472bf9ce36f8dae4add02a7" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" dependencies = [ - "redox_syscall", + "libredox", "wasite", "web-sys", ] @@ -2642,6 +2492,12 @@ dependencies = [ "safe_arch", ] +[[package]] +name = "widestring" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd7cf3379ca1aac9eea11fba24fd7e315d621f8dfe35c8d7d2be8b793726e07d" + [[package]] name = "winapi" version = "0.3.9" @@ -2660,11 +2516,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.1", ] [[package]] @@ -2679,11 +2535,23 @@ version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ - "windows-collections", - "windows-core", - "windows-future", - "windows-link", - "windows-numerics", + "windows-collections 0.2.0", + "windows-core 0.61.2", + "windows-future 0.2.1", + "windows-link 0.1.3", + "windows-numerics 0.2.0", +] + +[[package]] +name = "windows" +version = "0.62.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e6c4a1f363c8210c6f77ba24f645c61c6fb941eccf013da691f7e09515b8ac" +dependencies = [ + "windows-collections 0.3.1", + "windows-core 0.62.1", + "windows-future 0.3.1", + "windows-numerics 0.3.0", ] [[package]] @@ -2692,7 +2560,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ - "windows-core", + "windows-core 0.61.2", +] + +[[package]] +name = "windows-collections" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "123e712f464a8a60ce1a13f4c446d2d43ab06464cb5842ff68f5c71b6fb7852e" +dependencies = [ + "windows-core 0.62.1", ] [[package]] @@ -2703,9 +2580,22 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ "windows-implement", "windows-interface", - "windows-link", - "windows-result", - "windows-strings", + "windows-link 0.1.3", + "windows-result 0.3.4", + "windows-strings 0.4.2", +] + +[[package]] +name = "windows-core" +version = "0.62.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6844ee5416b285084d3d3fffd743b925a6c9385455f64f6d4fa3031c4c2749a9" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link 0.2.0", + "windows-result 0.4.0", + "windows-strings 0.5.0", ] [[package]] @@ -2714,31 +2604,42 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ - "windows-core", - "windows-link", - "windows-threading", + "windows-core 0.61.2", + "windows-link 0.1.3", + "windows-threading 0.1.0", +] + +[[package]] +name = "windows-future" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f3db6b24b120200d649cd4811b4947188ed3a8d2626f7075146c5d178a9a4a" +dependencies = [ + "windows-core 0.62.1", + "windows-link 0.2.0", + "windows-threading 0.2.0", ] [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.60.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "edb307e42a74fb6de9bf3a02d9712678b22399c87e6fa869d6dfcd8c1b7754e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.59.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "c0abd1ddbc6964ac14db11c7213d6532ef34bd9aa042c2e5935f59d7908b46a5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2747,14 +2648,30 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +[[package]] +name = "windows-link" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" + [[package]] name = "windows-numerics" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ - "windows-core", - "windows-link", + "windows-core 0.61.2", + "windows-link 0.1.3", +] + +[[package]] +name = "windows-numerics" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ce3498fe0aba81e62e477408383196b4b0363db5e0c27646f932676283b43d8" +dependencies = [ + "windows-core 0.62.1", + "windows-link 0.2.0", ] [[package]] @@ -2763,9 +2680,9 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a9ed28765efc97bbc954883f4e6796c33a06546ebafacbabee9696967499e" dependencies = [ - "windows-link", - "windows-result", - "windows-strings", + "windows-link 0.1.3", + "windows-result 0.3.4", + "windows-strings 0.4.2", ] [[package]] @@ -2774,7 +2691,16 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ - "windows-link", + "windows-link 0.1.3", +] + +[[package]] +name = "windows-result" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f" +dependencies = [ + "windows-link 0.2.0", ] [[package]] @@ -2783,7 +2709,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ - "windows-link", + "windows-link 0.1.3", +] + +[[package]] +name = "windows-strings" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda" +dependencies = [ + "windows-link 0.2.0", ] [[package]] @@ -2810,7 +2745,16 @@ version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.2", + "windows-targets 0.53.4", +] + +[[package]] +name = "windows-sys" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f109e41dd4a3c848907eb83d5a42ea98b3769495597450cf6d153507b166f0f" +dependencies = [ + "windows-link 0.2.0", ] [[package]] @@ -2831,10 +2775,11 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.2" +version = "0.53.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" +checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b" dependencies = [ + "windows-link 0.2.0", "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", "windows_i686_gnu 0.53.0", @@ -2851,7 +2796,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" dependencies = [ - "windows-link", + "windows-link 0.1.3", +] + +[[package]] +name = "windows-threading" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab47f085ad6932defa48855254c758cdd0e2f2d48e62a34118a268d8f345e118" +dependencies = [ + "windows-link 0.2.0", ] [[package]] @@ -2951,12 +2905,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "wl-clipboard-rs" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +checksum = "8e5ff8d0e60065f549fafd9d6cb626203ea64a798186c80d8e7df4f8af56baeb" dependencies = [ - "bitflags", + "libc", + "log", + "os_pipe", + "rustix 0.38.44", + "tempfile", + "thiserror", + "tree_magic_mini", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", ] [[package]] @@ -2965,6 +2935,23 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" +[[package]] +name = "x11rb" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414" +dependencies = [ + "gethostname", + "rustix 1.1.2", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd" + [[package]] name = "yoke" version = "0.8.0" @@ -2985,28 +2972,28 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure", ] [[package]] name = "zerocopy" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3026,7 +3013,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure", ] @@ -3043,9 +3030,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.2" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" dependencies = [ "yoke", "zerofrom", @@ -3060,5 +3047,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] diff --git a/Cargo.toml b/Cargo.toml index ebe6962..d17308d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,21 +10,21 @@ members = [ "cmd/pcfsserver", "cmd/setbridgeconfig", "pkg/cat-dev", - "pkg/log", ] resolver = "3" [workspace.dependencies] bytes = "^1.10.1" -clap = { version = "^4.5.40", features = ["color", "derive", "env", "error-context", "help", "suggestions", "unicode", "usage", "wrap_help"] } +clap = { version = "^4.5.48", features = ["color", "derive", "env", "error-context", "help", "suggestions", "unicode", "usage", "wrap_help"] } +chrono = "0.4.42" fnv = "^1.0.7" futures = "^0.3.31" mac_address = "^1.1.8" miette = { version = "^7.6.0", features = ["fancy"] } -network-interface = "^2.0.1" -time = "^0.3.41" +network-interface = "^2.0.3" +rm-lisa = "^0.1.1" tracing = { version = "^0.1.41", features = ["valuable"] } -tokio = { version = "^1.46.0", features = ["full", "tracing"] } +tokio = { version = "^1.47.1", features = ["full", "tracing"] } valuable = { version = "^0.1.1", features = ["derive"] } [workspace.package] diff --git a/cmd/bridgectl/Cargo.toml b/cmd/bridgectl/Cargo.toml index 862988c..f1b8fe2 100644 --- a/cmd/bridgectl/Cargo.toml +++ b/cmd/bridgectl/Cargo.toml @@ -14,10 +14,9 @@ cat-dev = { default-features = false, features = ["clients", "serial", "scientis clap.workspace = true fnv.workspace = true futures.workspace = true -log = { path = "../../pkg/log" } mac_address.workspace = true miette.workspace = true -terminal_size = "^0.4.2" +rm-lisa.workspace = true tokio.workspace = true tracing.workspace = true valuable.workspace = true diff --git a/cmd/bridgectl/src/commands/add.rs b/cmd/bridgectl/src/commands/add.rs index cbcc909..cc5376a 100644 --- a/cmd/bridgectl/src/commands/add.rs +++ b/cmd/bridgectl/src/commands/add.rs @@ -1,14 +1,11 @@ //! Handles the `add`, or `update` command for `bridgectl`. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{ get_targeted_bridge_ip, get_targeted_bridge_name, lease_bridge_config_mut, }, exit_codes::{ADD_COULD_NOT_SAVE_TO_DISK, ADD_COULD_NOT_UPSERT}, - utils::add_context_to, }; -use miette::miette; use tracing::{error, info}; /// Handle adding a bridge, or updating a bridge. @@ -18,34 +15,14 @@ pub async fn handle_add_or_update(set_default: bool) { let mut host_state = lease_bridge_config_mut().await; if let Err(cause) = host_state.upsert_bridge(&bridge_name, bridge_ip) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::add::upsert_failed", - ?cause, - %bridge_name, - %bridge_ip, - "Please ensure bridge name we're adding is a valid bridge name.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not add bridge to host state file, bridge name must not be valid." - ), - [ - cause.into(), - miette!( - help = format!( - "Arguments were: Bridge Name: {bridge_name} / Bridge IP: {bridge_ip}" - ), - "Bridge Names must be ASCII, and between 1-255 characters long.", - ), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::add::upsert_failed", + ?cause, + %bridge_name, + %bridge_ip, + help = "Bridge names must be ASCII, and between 1-255 characters long.", + "Please ensure bridge name we're adding is a valid bridge name.", + ); std::process::exit(ADD_COULD_NOT_UPSERT); } @@ -56,31 +33,23 @@ pub async fn handle_add_or_update(set_default: bool) { } if let Err(cause) = host_state.write_to_disk().await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::add::write_to_disk_failure", - ?cause, - path = %host_state.get_path().display(), - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!("Host state path is: {}", host_state.get_path().display()), - "Could not write the new host state file to disk! Change is not persisted!" - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::add::write_to_disk_failure", + ?cause, + path = %host_state.get_path().display(), + ); std::process::exit(ADD_COULD_NOT_SAVE_TO_DISK); } + let mut line = "Successfully added a bridge to your host state file!{}".to_owned(); + if set_default { + line += " And successfully set it as your default bridge."; + } info!( id = "bridgectl::add::success", %bridge_name, %bridge_ip, - "Successfully added a bridge to your host state file!{}", - if set_default { " And successfully set it as your default bridge." } else { "" } + line, ); } diff --git a/cmd/bridgectl/src/commands/argv_helpers/bridge_conf.rs b/cmd/bridgectl/src/commands/argv_helpers/bridge_conf.rs index cd9b147..f7abdc5 100644 --- a/cmd/bridgectl/src/commands/argv_helpers/bridge_conf.rs +++ b/cmd/bridgectl/src/commands/argv_helpers/bridge_conf.rs @@ -7,13 +7,10 @@ //! have these series of functions which wrap around a static safely. use crate::{ - SHOULD_LOG_JSON, exit_codes::{ARGV_BRIDGE_STATE_LOAD_FAILURE, ARGV_NO_BRIDGE_STATE_PATH}, knobs::{cli::BridgeConfigurationFlags, env::BRIDGE_HOST_STATE_PATH}, - utils::add_context_to, }; use cat_dev::mion::BridgeHostState; -use miette::miette; use std::path::PathBuf; use tokio::sync::{RwLock, RwLockMappedWriteGuard, RwLockReadGuard, RwLockWriteGuard}; use tracing::{error, field::valuable, info}; @@ -29,16 +26,10 @@ static BRIDGE_ENV_PATH: RwLock> = RwLock::const_new(None); pub async fn initialize_host_bridge(bridge_config_flags: BridgeConfigurationFlags) { let system_default_path = BridgeHostState::get_default_host_path(); if system_default_path.is_none() { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::no_default_host_state_path", - "looks like your OS doesn't have a default host state path, please file an issue to support your OS better", - ); - } else { - info!( - "Hey! It looks like we don't have a default path configured for the bridge configuration file. This may mean certain features like setting a default bridge won't work! You can always manually specify a manual place to store the file with `--bridge-state-path`, but we'd really appreciate if you filed an issue to support your OS better!" - ); - } + info!( + id = "bridgectl::argv::no_default_host_state_path", + "looks like your OS doesn't have a default host state path, please file an issue to support your OS better", + ); } if let Some(cli_arg) = bridge_config_flags.bridge_state_path() { @@ -108,29 +99,15 @@ async fn try_to_load_bridge_config() { let read_env_path = BRIDGE_ENV_PATH.read().await; if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::bridge_state_path_required", - cause = "Could not find the bridge state path aka `bridge_env.ini`", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", - "You can specify the path manually with a cli argument: [`--bridge-state-path`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the path to store the bridge-host state file!"), - [ - miette!("You can specify the path to the `bridge_env.ini` file with the environment variable `BRIDGECTL_BRIDGE_ENV_PATH`"), - miette!("You can specify the path to the `bridge_env.ini` file with the cli argument `--bridge-state-path`"), - miette!("You can file an issue with the project to choose a default directory for your OS."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::bridge_state_path_required", + help = valuable(&[ + "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", + "You can specify the path manually with a cli argument: [`--bridge-state-path`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + "Could not find the bridge state path aka `bridge_env.ini`", + ); return; } let host_state_path = read_env_path.as_ref().expect("impossible"); @@ -140,26 +117,12 @@ async fn try_to_load_bridge_config() { _ = write_lock.insert(state); } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_host_state", - ?cause, - host_state_path = %host_state_path.display(), - "failed to load host state file", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "Host State File is located at: {}", - host_state_path.display() - ), - "Cannot load host state file!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_host_state", + ?cause, + host_state_path = %host_state_path.display(), + "failed to load host state file", + ); } } } @@ -187,29 +150,15 @@ async fn validate_bridge_config_is_populated() { let read_env_path = BRIDGE_ENV_PATH.read().await; if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::bridge_state_path_required", - cause = "Could not find the bridge state path aka `bridge_env.ini`", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", - "You can specify the path manually with a cli argument: [`--bridge-state-path`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the path to store the bridge-host state file!"), - [ - miette!("You can specify the path to the `bridge_env.ini` file with the environment variable `BRIDGECTL_BRIDGE_ENV_PATH`"), - miette!("You can specify the path to the `bridge_env.ini` file with the cli argument `--bridge-state-path`"), - miette!("You can file an issue with the project to choose a default directory for your OS."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::bridge_state_path_required", + help = valuable(&[ + "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", + "You can specify the path manually with a cli argument: [`--bridge-state-path`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + "Could not find the bridge state path aka `bridge_env.ini`", + ); std::process::exit(ARGV_NO_BRIDGE_STATE_PATH); } @@ -220,26 +169,12 @@ async fn validate_bridge_config_is_populated() { _ = write_lock.insert(state); } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_host_state", - ?cause, - host_state_path = %host_state_path.display(), - "failed to load host state file", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "Host State File is located at: {}", - host_state_path.display() - ), - "Cannot load host state file!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_host_state", + ?cause, + host_state_path = %host_state_path.display(), + "failed to load host state file", + ); std::process::exit(ARGV_BRIDGE_STATE_LOAD_FAILURE); } diff --git a/cmd/bridgectl/src/commands/argv_helpers/bridge_target.rs b/cmd/bridgectl/src/commands/argv_helpers/bridge_target.rs index 6a91cc7..1ce6b2d 100644 --- a/cmd/bridgectl/src/commands/argv_helpers/bridge_target.rs +++ b/cmd/bridgectl/src/commands/argv_helpers/bridge_target.rs @@ -44,19 +44,18 @@ //! but obviously the fastest will be when we don't have to do a lookup at all. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{ get_control_port, get_scan_timeout, lease_bridge_config, lease_bridge_config_optionally, }, exit_codes::{ ARGV_BRIDGE_CONFLICTING_ARGUMENTS, ARGV_COULD_NOT_GET_DEFAULT_BRIDGE, ARGV_COULD_NOT_SEARCH_FOR_BRIDGE, ARGV_NO_BRIDGE_ENV, ARGV_NO_BRIDGE_SPECIFIED, + SHOULD_NEVER_HAPPEN_FAILURE, }, knobs::{ cli::TargetBridgeFlags, env::{BRIDGE_CURRENT_IP_ADDRESS, BRIDGE_CURRENT_NAME}, }, - utils::add_context_to, }; use cat_dev::mion::{ BridgeHostState, @@ -64,7 +63,6 @@ use cat_dev::mion::{ proto::control::MionIdentity, }; use mac_address::MacAddress; -use miette::miette; use std::{net::Ipv4Addr, time::Duration}; use tokio::sync::{RwLock, RwLockReadGuard}; use tracing::{debug, error, field::valuable, info, warn}; @@ -111,41 +109,21 @@ pub async fn target_bridge( } if !try_to_load_from_env().await { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::default_fallback", - "No bridge specified in environment, and argument is missing or _may_ not be bridge name, trying to load default from configuration.", - ); - } else { - info!( - "No bridge specified in environment, and argument is missing or _may_ not be a bridge name, trying to load default from configuration." - ); - } + info!( + id = "bridgectl::argv::default_fallback", + "No bridge specified in environment, and argument is missing or _may_ not be bridge name, trying to load default from configuration.", + ); if !try_to_load_default().await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::no_bridge_found", - help_items = valuable(&[ - "You can specify a bridge with environment variables `BRIDGE_CURRENT_NAME`, `BRIDGE_CURRENT_IP_ADDRESS`.", - "You can specify one with flags `--ip`, `--mac`, or `--name`.", - "You can set a default bridge in your configuration file (see `bridgectl set-default`, or `bridgectl add --default`).", - ]), - "Command needs to target a single bridge, and you didn't specify a single bridge to use.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Command needs to target a single bridge, and you didn't specify a single bridge to use."), - [ - miette!("You can specify a bridge with environment variables `BRIDGE_CURRENT_NAME`, or `BRIDGE_CURRENT_IP_ADDRESS` (these get set by cafex/mochiato too)."), - miette!("You can specify one with flags `--ip`, `--mac`, or `--name`."), - miette!("You can set a default bridge in your configuration file (see `bridgectl set-default`, or `bridgectl add --default`"), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::no_bridge_found", + help = valuable(&[ + "You can specify a bridge with environment variables `BRIDGE_CURRENT_NAME`, `BRIDGE_CURRENT_IP_ADDRESS`.", + "You can specify one with flags `--ip`, `--mac`, or `--name`.", + "You can set a default bridge in your configuration file (see `bridgectl set-default`, or `bridgectl add --default`).", + ]), + "Command needs to target a single bridge, and you didn't specify a single bridge to use.", + ); std::process::exit(ARGV_NO_BRIDGE_SPECIFIED); } @@ -216,28 +194,15 @@ async fn resolve_mac_from_ip(mion_ip: Ipv4Addr) -> MacAddress { match find_mion(MIONFindBy::Ip(mion_ip), false, Some(timeout), Some(port)).await { Ok(opt_mion_info) => get_mion_mac_from_scan_result(opt_mion_info, mion_ip, port, timeout), Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::failed_to_execute_search", - ?cause, - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - help = "Perhaps another program is already using the single MION port?", - "Could not execute search for bridge...", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not send a packet directly to the IP specified, perhaps it wasn't reachable?", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::failed_to_execute_search", + ?cause, + filters.find_by = %MIONFindBy::Ip(mion_ip), + scanning.port = %port, + scanning.timeout_seconds = timeout.as_secs(), + help = "Perhaps another program is already using the single MION port?", + "Could not execute search for bridge...", + ); std::process::exit(ARGV_COULD_NOT_SEARCH_FOR_BRIDGE); } @@ -247,12 +212,11 @@ async fn resolve_mac_from_ip(mion_ip: Ipv4Addr) -> MacAddress { async fn resolve_name_from_ip(mion_ip: Ipv4Addr) -> String { // First check environment, they may have passed a flag, but the other info // was already in the environment. - if let Some(ip_addr) = BRIDGE_CURRENT_IP_ADDRESS.as_ref() { - if let Some(name) = BRIDGE_CURRENT_NAME.as_ref() { - if mion_ip == *ip_addr { - return name.to_owned(); - } - } + if let Some(ip_addr) = BRIDGE_CURRENT_IP_ADDRESS.as_ref() + && let Some(name) = BRIDGE_CURRENT_NAME.as_ref() + && mion_ip == *ip_addr + { + return name.to_owned(); } // Next check the config file for a bridge defined with that ip. if let Some(bridge_conf) = lease_bridge_config_optionally().await { @@ -263,6 +227,7 @@ async fn resolve_name_from_ip(mion_ip: Ipv4Addr) -> String { expected.ip = %mion_ip, found.ip = %bip, filtering.is_equal = bip == mion_ip, + "checking bridge ip equality", ); if bip == mion_ip { return bridge_name; @@ -276,18 +241,11 @@ async fn resolve_name_from_ip(mion_ip: Ipv4Addr) -> String { } // If we're able to do nothing else, we're relegated to do a search - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::have_bridge_ip_looking_up_name", - suggestion = "In order to prevent lookups being necessary, feel free to add this name/ip to your bridge configuration file (with `bridgectl add`).", - "We have a Bridge IP, but can't find a bridge name in environment/configuration files.", - ); - } else { - info!( - suggestion = "In order to prevent lookups being necessary, feel free to add this bridge name/ip to your bridge configuration file (with `bridgectl add`).", - "We have a Bridge IP, but can't find a bridge name in environment/configuration files.", - ); - } + info!( + id = "bridgectl::argv::have_bridge_ip_looking_up_name", + help = "In order to prevent lookups being necessary, feel free to add this name/ip to your bridge configuration file (with `bridgectl add`).", + "We have a Bridge IP, but can't find a bridge name in environment/configuration files.", + ); let port = get_control_port().await; let timeout = get_scan_timeout().await; @@ -298,28 +256,15 @@ async fn resolve_name_from_ip(mion_ip: Ipv4Addr) -> String { get_mion_name_from_scan_result(opt_mion_info, mion_ip, port, timeout) } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::failed_to_execute_search", - ?cause, - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - help = "Perhaps another program is already using the single MION port?", - "Could not execute search for bridge...", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not send a packet directly to the IP specified, perhaps it wasn't reachable?", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::failed_to_execute_search", + ?cause, + filters.find_by = %MIONFindBy::Ip(mion_ip), + scanning.port = %port, + scanning.timeout_seconds = timeout.as_secs(), + help = "Perhaps another program is already using the single MION port?", + "Could not execute search for bridge...", + ); std::process::exit(ARGV_COULD_NOT_SEARCH_FOR_BRIDGE); } @@ -329,12 +274,11 @@ async fn resolve_name_from_ip(mion_ip: Ipv4Addr) -> String { async fn resolve_ip_from_name(mion_name: String) -> Ipv4Addr { // First check environment, they may have passed a flag, but the other info // was already in the environment. - if let Some(ip_addr) = BRIDGE_CURRENT_IP_ADDRESS.as_ref() { - if let Some(name) = BRIDGE_CURRENT_NAME.as_ref() { - if name.as_str() == mion_name.as_str() { - return ip_addr.to_owned(); - } - } + if let Some(ip_addr) = BRIDGE_CURRENT_IP_ADDRESS.as_ref() + && let Some(name) = BRIDGE_CURRENT_NAME.as_ref() + && name.as_str() == mion_name.as_str() + { + return ip_addr.to_owned(); } // Next check the config file for a bridge defined with that ip. if let Some(bridge_conf) = lease_bridge_config_optionally().await { @@ -352,18 +296,11 @@ async fn resolve_ip_from_name(mion_name: String) -> Ipv4Addr { } // If we're able to do nothing else, we're relegated to do a search - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::have_bridge_name_looking_up_ip", - suggestion = "In order to prevent lookups being necessary, feel free to add this name/ip to your bridge configuration file (with `bridgectl add`).", - "We have a Bridge Name, but can't find a Bridge IP in environment/configuration files.", - ); - } else { - info!( - suggestion = "In order to prevent lookups being necessary, feel free to add this bridge name/ip to your bridge configuration file (with `bridgectl add`).", - "We have a Bridge Name, but can't find a Bridge IP in environment/configuration files.", - ); - } + info!( + id = "bridgectl::argv::have_bridge_name_looking_up_ip", + help = "In order to prevent lookups being necessary, feel free to add this name/ip to your bridge configuration file (with `bridgectl add`).", + "We have a Bridge Name, but can't find a Bridge IP in environment/configuration files.", + ); let port = get_control_port().await; let timeout = get_scan_timeout().await; @@ -381,28 +318,15 @@ async fn resolve_ip_from_name(mion_name: String) -> Ipv4Addr { get_mion_ip_from_scan_result(opt_mion_info, mion_name, port, timeout) } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::failed_to_execute_search", - ?cause, - filters.find_by = %MIONFindBy::Name(mion_name), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - help = "Perhaps another program is already using the single MION port?", - "Could not execute search for bridge...", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Name(mion_name), - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not send a packet directly to the IP specified, perhaps it wasn't reachable?", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::failed_to_execute_search", + ?cause, + filters.find_by = %MIONFindBy::Name(mion_name), + scanning.port = %port, + scanning.timeout_seconds = timeout.as_secs(), + help = "Perhaps another program is already using the single MION port?", + "Could not execute search for bridge...", + ); std::process::exit(ARGV_COULD_NOT_SEARCH_FOR_BRIDGE); } @@ -434,39 +358,19 @@ fn get_mion_mac_from_scan_result( return result.mac_address(); } - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::search_returned_no_bridges", - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - suggestions = valuable(&[ - "Please ensure the CAT-DEV you're trying to find is powered on, and running.", - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", - "Ensure your filters line up with a single CAT-DEV device.", - ]), - "could not find a bridge with the filters on your network.", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - add_context_to( - miette!( - "Could not find a bridge that matches your filters on your network.", - ), - [ - miette!("Please ensure the CAT-DEV you're trying to find is powered on, and running."), - miette!("Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device."), - miette!("If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans."), - miette!("Ensure your filters line up with a single CAT-DEV device."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::search_returned_no_bridges", + filters.find_by = %MIONFindBy::Ip(mion_ip), + scanning.port = port, + scanning.timeout_seconds = timeout.as_secs(), + help = valuable(&[ + "Please ensure the CAT-DEV you're trying to find is powered on, and running.", + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", + "Ensure your filters line up with a single CAT-DEV device.", + ]), + "could not find a bridge with the filters on your network.", + ); std::process::exit(ARGV_NO_BRIDGE_SPECIFIED); } @@ -481,39 +385,19 @@ fn get_mion_ip_from_scan_result( return result.ip_address(); } - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::search_returned_no_bridges", - filters.find_by = %MIONFindBy::Name(mion_name), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - suggestions = valuable(&[ - "Please ensure the CAT-DEV you're trying to find is powered on, and running.", - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", - "Ensure your filters line up with a single CAT-DEV device.", - ]), - "could not find a bridge with the filters on your network.", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Name(mion_name), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - add_context_to( - miette!( - "Could not find a bridge that matches your filters on your network.", - ), - [ - miette!("Please ensure the CAT-DEV you're trying to find is powered on, and running."), - miette!("Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device."), - miette!("If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans."), - miette!("Ensure your filters line up with a single CAT-DEV device."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::search_returned_no_bridges", + filters.find_by = %MIONFindBy::Name(mion_name), + scanning.port = port, + scanning.timeout_seconds = timeout.as_secs(), + help = valuable(&[ + "Please ensure the CAT-DEV you're trying to find is powered on, and running.", + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", + "Ensure your filters line up with a single CAT-DEV device.", + ]), + "could not find a bridge with the filters on your network.", + ); std::process::exit(ARGV_NO_BRIDGE_SPECIFIED); } @@ -528,39 +412,19 @@ fn get_mion_name_from_scan_result( return result.name().to_owned(); } - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::search_returned_no_bridges", - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - suggestions = valuable(&[ - "Please ensure the CAT-DEV you're trying to find is powered on, and running.", - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", - "Ensure your filters line up with a single CAT-DEV device.", - ]), - "could not find a bridge with the filters on your network.", - ); - } else { - error!( - filters.find_by = %MIONFindBy::Ip(mion_ip), - scanning.port = port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - add_context_to( - miette!( - "Could not find a bridge that matches your filters on your network.", - ), - [ - miette!("Please ensure the CAT-DEV you're trying to find is powered on, and running."), - miette!("Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device."), - miette!("If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans."), - miette!("Ensure your filters line up with a single CAT-DEV device."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::search_returned_no_bridges", + filters.find_by = %MIONFindBy::Ip(mion_ip), + scanning.port = port, + scanning.timeout_seconds = timeout.as_secs(), + help = valuable(&[ + "Please ensure the CAT-DEV you're trying to find is powered on, and running.", + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", + "Ensure your filters line up with a single CAT-DEV device.", + ]), + "could not find a bridge with the filters on your network.", + ); std::process::exit(ARGV_NO_BRIDGE_SPECIFIED); } @@ -584,18 +448,11 @@ async fn target_search_flags( false, ) } else { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::argv::mac_flag_invalid", - mac_flag = ?target_flags.search_for_mac_raw(), - "Mac Flag is not a valid MAC Address, will not be used, and will exit if no other filters present." - ); - } else { - warn!( - mac_flag = ?target_flags.search_for_mac_raw(), - "Mac Flag is not a valid MAC Address, will not be used, and will exit if no other filters present." - ); - } + warn!( + id = "bridgectl::argv::mac_flag_invalid", + mac_flag = ?target_flags.search_for_mac_raw(), + "Mac Flag is not a valid MAC Address, will not be used, and will exit if no other filters present." + ); if target_flags.search_for_ip().is_none() && target_flags.search_for_name().is_none() @@ -630,9 +487,10 @@ async fn target_search_flags( return None; } - panic!( + error!( "internal_error: target_search_flags() called when no search flags were specified", ); + std::process::exit(SHOULD_NEVER_HAPPEN_FAILURE); }; match MIONFindBy::from(argument.to_owned()) { @@ -670,28 +528,16 @@ async fn do_scan_initial( let port = get_control_port().await; let timeout = get_scan_timeout().await; - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::scanning_for_bridge", - reason = "A MAC Address was specified, so we're scanning to confirm all information is correct.", - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "looking up MION to target", - ); - } else { - info!( - reason = "A MAC Address was specified, so we're scanning to confirm all information is correct.", - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "Looking up MION bridge to target", - ); - } + info!( + id = "bridgectl::argv::scanning_for_bridge", + reason = "A MAC Address was specified, so we're scanning to confirm all information is correct.", + filters.find_by = %find_by, + filters.extra_ip_filter = ?extra_ip_filter, + filters.extra_name_filter = ?extra_name_filter, + scanning.port = %port, + scanning.timeout_seconds = timeout.as_secs(), + "looking up MION to target", + ); match find_mion(find_by.clone(), false, Some(timeout), Some(port)).await { Ok(opt_mion_info) => { @@ -707,32 +553,17 @@ async fn do_scan_initial( } Err(cause) => { if should_exit { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::failed_to_execute_search", - ?cause, - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - help = "Perhaps another program is already using the single MION port?", - "Could not execute search for bridge...", - ); - } else { - error!( - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = %port, - scanning.timeout_seconds = timeout.as_secs(), - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not send a packet directly to the IP specified, perhaps it wasn't reachable?", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::failed_to_execute_search", + ?cause, + filters.find_by = %find_by, + filters.extra_ip_filter = ?extra_ip_filter, + filters.extra_name_filter = ?extra_name_filter, + scanning.port = %port, + scanning.timeout_seconds = timeout.as_secs(), + help = "Perhaps another program is already using the single MION port?", + "Could not execute search for bridge...", + ); std::process::exit(ARGV_COULD_NOT_SEARCH_FOR_BRIDGE); } @@ -753,15 +584,15 @@ async fn process_found_mion( if let Some(result) = found_result { let mut matches_all = true; - if let Some(ip_filter) = extra_ip_filter { - if result.ip_address() != ip_filter { - matches_all = false; - } + if let Some(ip_filter) = extra_ip_filter + && result.ip_address() != ip_filter + { + matches_all = false; } - if let Some(name_filter) = extra_name_filter { - if result.name() != name_filter { - matches_all = false; - } + if let Some(name_filter) = extra_name_filter + && result.name() != name_filter + { + matches_all = false; } if matches_all { @@ -774,43 +605,21 @@ async fn process_found_mion( } } - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::search_returned_no_bridges", - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = scan_port, - scanning.timeout_seconds = scan_timeout.as_secs(), - suggestions = valuable(&[ - "Please ensure the CAT-DEV you're trying to find is powered on, and running.", - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", - "Ensure your filters line up with a single CAT-DEV device.", - ]), - "could not find a bridge with the filters on your network.", - ); - } else { - error!( - filters.find_by = %find_by, - filters.extra_ip_filter = ?extra_ip_filter, - filters.extra_name_filter = ?extra_name_filter, - scanning.port = scan_port, - scanning.timeout_seconds = scan_timeout.as_secs(), - "\n{:?}", - add_context_to( - miette!( - "Could not find a bridge that matches your filters on your network.", - ), - [ - miette!("Please ensure the CAT-DEV you're trying to find is powered on, and running."), - miette!("Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device."), - miette!("If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans."), - miette!("Ensure your filters line up with a single CAT-DEV device."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::search_returned_no_bridges", + filters.find_by = %find_by, + filters.extra_ip_filter = ?extra_ip_filter, + filters.extra_name_filter = ?extra_name_filter, + scanning.port = scan_port, + scanning.timeout_seconds = scan_timeout.as_secs(), + help = valuable(&[ + "Please ensure the CAT-DEV you're trying to find is powered on, and running.", + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", + "Ensure your filters line up with a single CAT-DEV device.", + ]), + "could not find a bridge with the filters on your network.", + ); std::process::exit(ARGV_NO_BRIDGE_SPECIFIED); } @@ -859,31 +668,15 @@ async fn target_default_or_mochiato( if target_flags.specified_bridge_search_flag() || (first_arg_must_be_bridge && specified_first_arg) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::flags_conflict_on_device_search", - targeting_flags = valuable(&target_flags), - suggestions = valuable(&[ - "If you want to fetch the default bridge all you need is to specify the `--default` flag, you don't need anything else.", - "If you want to apply extra filtering to the output we recommend changing the log format to JSON, and doing the extra filtering using a tool like `jq`.", - ]), - "We were told to not search and just use either the default bridge, or environment. While also being told to search for another device! Not sure which to do.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Cannot specify search filters `--ip`/`--mac`/`--name` while also telling us to not search with `--default`, or `--bridge-from-env`!"), - [ - miette!("If you just want to fetch the default bridge, or bridge from the environment, you do not need to specify the search flags, we will find it for you."), - miette!( - help = format!("{target_flags}"), - "If you want to apply extra filtering on the output, or query some inner field feel free to output logs as JSON, and use `jq` to programatically interpret/fetch/filter the results." - ), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::flags_conflict_on_device_search", + targeting_flags = valuable(&target_flags), + help = valuable(&[ + "If you want to fetch the default bridge all you need is to specify the `--default` flag, you don't need anything else.", + "If you want to apply extra filtering to the output we recommend changing the log format to JSON, and doing the extra filtering using a tool like `jq`.", + ]), + "We were told to not search and just use either the default bridge, or environment. While also being told to search for another device! Not sure which to do.", + ); std::process::exit(ARGV_BRIDGE_CONFLICTING_ARGUMENTS); } else if target_flags.target_default() { @@ -895,31 +688,15 @@ async fn target_default_or_mochiato( async fn load_bridge_from_default(config: RwLockReadGuard<'_, BridgeHostState>) { let Some((bridge_name, opt_ip)) = config.get_default_bridge() else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::no_default_bridge", - host_state_path = %config.get_path().display(), - suggestions = valuable(&[ - "Please double check the configuration file located at the path specified, and ensure `BRIDGE_DEFAULT_NAME` is set to a real bridge name.", - "If the bridge isn't set as the default you can use `bridge add --default `, or `bridge set-default <'name' or 'ip'>`.", - ]), - "No default bridge present in configuration file.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("No default bridge present in the configuration file."), - [ - miette!("Please double check the configuration file located at the path specified, and ensure `BRIDGE_DEFAULT_NAME` is set to a real bridge name."), - miette!( - help = format!("The bridge configuration file was located at: {}", config.get_path().display()), - "If the bridge isn't set as the default you can use `bridge add --default `, or `bridge set-default <'name' or 'ip'>`.", - ), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::no_default_bridge", + host_state_path = %config.get_path().display(), + help = valuable(&[ + "Please double check the configuration file located at the path specified, and ensure `BRIDGE_DEFAULT_NAME` is set to a real bridge name.", + "If the bridge isn't set as the default you can use `bridge add --default `, or `bridge set-default <'name' or 'ip'>`.", + ]), + "No default bridge present in configuration file.", + ); std::process::exit(ARGV_COULD_NOT_GET_DEFAULT_BRIDGE); }; @@ -937,21 +714,12 @@ async fn load_bridge_from_default(config: RwLockReadGuard<'_, BridgeHostState>) async fn load_from_mochiato() { if BRIDGE_CURRENT_NAME.is_none() && BRIDGE_CURRENT_IP_ADDRESS.is_none() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::no_bridge_environment", - help = "You can use `cafex`/`mochiato` shells to set these environment variables for you.", - "We were told to use the bridge from the environment, but `BRIDGE_CURRENT_NAME` & `BRIDGE_CURRENT_IP_ADDRESS` are not set!", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "You can use `cafex`/`mochiato` shells to set these environment variables for you.", - "We were told to use the bridge for the environment, but `BRIDGE_CURRENT_NAME` & `BRIDGE_CURRENT_IP_ADDRESS` are not set!", - ), - ); - } + error!( + id = "bridgectl::argv::no_bridge_environment", + help = + "You can use `cafex`/`mochiato` shells to set these environment variables for you.", + "We were told to use the bridge from the environment, but `BRIDGE_CURRENT_NAME` & `BRIDGE_CURRENT_IP_ADDRESS` are not set!", + ); std::process::exit(ARGV_NO_BRIDGE_ENV); } diff --git a/cmd/bridgectl/src/commands/argv_helpers/fsemul_conf.rs b/cmd/bridgectl/src/commands/argv_helpers/fsemul_conf.rs index 473ff5c..5e85f73 100644 --- a/cmd/bridgectl/src/commands/argv_helpers/fsemul_conf.rs +++ b/cmd/bridgectl/src/commands/argv_helpers/fsemul_conf.rs @@ -7,19 +7,16 @@ //! have these series of functions which wrap around a static safely. use crate::{ - SHOULD_LOG_JSON, exit_codes::{ ARGV_CAFE_ROOT_LOAD_FAILURE, ARGV_FSEMUL_LOAD_FAILURE, ARGV_NO_CAFE_ROOT, - ARGV_NO_FSEMUL_PATH, + ARGV_NO_FSEMUL_PATH, HOST_FILESYSTEM_INIT_FAILURE, }, knobs::{ cli::FSEmulConfigurationFlags, env::{CAFE_ROOT, FSMEUL_CONFIG_PATH as FSEMUL_CONFIG_PATH_ENV_ARG}, }, - utils::add_context_to, }; use cat_dev::fsemul::{FSEmulConfig, HostFilesystem}; -use miette::miette; use std::{ path::PathBuf, sync::{ @@ -45,29 +42,17 @@ static FORCE_UNIQUE_FDS: AtomicBool = AtomicBool::new(false); pub async fn initialize_fsemul_config(fsemul_config_flags: &FSEmulConfigurationFlags) { let fsemul_default_path = FSEmulConfig::get_default_host_path(); if fsemul_default_path.is_none() { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::no_default_fsemul_config_path", - "looks like your OS doesn't have a default fsemul config path, please file an issue to support your OS better", - ); - } else { - info!( - "Hey! It looks like we don't have a default path configured for the fsemul configuration file. This may mean certain configuration options for fsemul may not work! You can always manually specify a manual place to store the file with `--fsemul-config-path`, but we'd really appreciate if you filed an issue to support your OS better!" - ); - } + info!( + id = "bridgectl::argv::no_default_fsemul_config_path", + "looks like your OS doesn't have a default fsemul config path, please file an issue to support your OS better", + ); } let host_default_path = HostFilesystem::default_cafe_folder(); if host_default_path.is_none() { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::argv::no_default_host_filesystem_path", - "looks like your OS doesn't have a default host filesystem path, please file an issue to support your OS better", - ); - } else { - info!( - "Hey! It looks like we don't have a default path configured for the cafe sdk data directory. This may mean certain configuration options for fsemul may not work! You can always manually specify a manual place to store the file with `--fsemul-config-path`, but we'd really appreciate if you filed an issue to support your OS better!" - ); - } + info!( + id = "bridgectl::argv::no_default_host_filesystem_path", + "looks like your OS doesn't have a default host filesystem path, please file an issue to support your OS better", + ); } if fsemul_config_flags.force_unique_fds() { FORCE_UNIQUE_FDS.store(true, Ordering::SeqCst); @@ -169,29 +154,15 @@ async fn try_to_load_fsemul_config() { let read_env_path = FSEMUL_CONFIG_PATH.read().await; if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::bridge_state_path_required", - cause = "Could not find the bridge state path aka `bridge_env.ini`", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", - "You can specify the path manually with a cli argument: [`--bridge-state-path`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the path to store the bridge-host state file!"), - [ - miette!("You can specify the path to the `bridge_env.ini` file with the environment variable `BRIDGECTL_BRIDGE_ENV_PATH`"), - miette!("You can specify the path to the `bridge_env.ini` file with the cli argument `--bridge-state-path`"), - miette!("You can file an issue with the project to choose a default directory for your OS."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::bridge_state_path_required", + cause = "Could not find the bridge state path aka `bridge_env.ini`", + suggestions = valuable(&[ + "You can specify the path manually with an environment variable: [`BRIDGECTL_BRIDGE_ENV_PATH`]", + "You can specify the path manually with a cli argument: [`--bridge-state-path`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + ); return; } let fsemul_path = read_env_path.as_ref().expect("impossible"); @@ -201,26 +172,12 @@ async fn try_to_load_fsemul_config() { _ = write_lock.insert(state); } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_fsemul_configuration", - ?cause, - fsemul_path = %fsemul_path.display(), - "failed to load fsemul configuration file", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "FSEMul Configuration File is located at: {}", - fsemul_path.display() - ), - "Cannot load fsemul configuration file!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_fsemul_configuration", + ?cause, + fsemul_path = %fsemul_path.display(), + "failed to load fsemul configuration file", + ); } } } @@ -231,65 +188,38 @@ async fn try_to_load_host_file_system() { _ = HOST_FILE_SYSTEM.get_or_init(|| { if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::host_filesystem_required", - cause = "Could not load the cafe root directory, to serve a host filesystem out of", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`CAFE_ROOT`]", - "You can specify the path manually with a cli argument: [`--cafe-path`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the path to load the root cafe root directory!"), - [ - miette!("You can specify the path to the `bridge_env.ini` file with the environment variable `CAFE_ROOT`"), - miette!("You can specify the path to the `bridge_env.ini` file with the cli argument `--cafe-path`"), - miette!("You can file an issue with the project to choose a default directory for your OS."), - ].into_iter(), - ), - ); - } - panic!("Failed to find CAFE_ROOT!"); + error!( + id = "bridgectl::argv::host_filesystem_required", + cause = "Could not load the cafe root directory, to serve a host filesystem out of", + suggestions = valuable(&[ + "You can specify the path manually with an environment variable: [`CAFE_ROOT`]", + "You can specify the path manually with a cli argument: [`--cafe-path`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + ); + std::process::exit(ARGV_NO_CAFE_ROOT); } let host_fs_path = read_env_path.as_ref().expect("impossible"); - match futures::executor::block_on(HostFilesystem::from_cafe_dir(Some(host_fs_path.clone()))) { + match futures::executor::block_on(HostFilesystem::from_cafe_dir(Some(host_fs_path.clone()))) + { Ok(mut state) => { if FORCE_UNIQUE_FDS.load(Ordering::SeqCst) { // This is guaranteed to work, the host filesystem _just_ created. std::mem::drop(state.force_unique_fds()); } state - }, + } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_host_file_system", - ?cause, - host_fs_path = %host_fs_path.display(), - "failed to load cafe root directory", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "Cafe Root Directory is located at: {}", - host_fs_path.display() - ), - "Cannot load fsemul configuration file!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_host_file_system", + ?cause, + host_fs_path = %host_fs_path.display(), + "failed to load cafe root directory", + ); - panic!("Failed to bootstrap host filesystem!"); + std::process::exit(HOST_FILESYSTEM_INIT_FAILURE); } } }); @@ -317,29 +247,16 @@ async fn validate_fsemul_config_is_populated() { let read_env_path = FSEMUL_CONFIG_PATH.read().await; if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::fsemul_path_required", - cause = "Could not find the fsemul path aka `fsemul.ini`", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`BRIDGECTL_FSEMUL_PATH`]", - "You can specify the path manually with a cli argument: [`--fsemul-config-path`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the path to store the fsemul config file!"), - [ - miette!("You can specify the path to the `bridge_env.ini` file with the environment variable `BRIDGECTL_FSEMUL_PATH`"), - miette!("You can specify the path to the `bridge_env.ini` file with the cli argument `--fsemul-config-path`"), - miette!("You can file an issue with the project to choose a default directory for your OS."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::fsemul_path_required", + cause = "Could not find the fsemul path aka `fsemul.ini`", + help = valuable(&[ + "You can specify the path manually with an environment variable: [`BRIDGECTL_FSEMUL_PATH`]", + "You can specify the path manually with a cli argument: [`--fsemul-config-path`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + "Failed to find FSEmul path!", + ); std::process::exit(ARGV_NO_FSEMUL_PATH); } @@ -350,26 +267,12 @@ async fn validate_fsemul_config_is_populated() { _ = write_lock.insert(state); } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_fsemul_config", - ?cause, - fsemul_config_path = %fsemul_config_path.display(), - "failed to load fsemul configuration file", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "FSEmul Configuration File is located at: {}", - fsemul_config_path.display() - ), - "Cannot load fsemul configuration file!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_fsemul_config", + ?cause, + fsemul_config_path = %fsemul_config_path.display(), + "failed to load fsemul configuration file", + ); std::process::exit(ARGV_FSEMUL_LOAD_FAILURE); } @@ -382,36 +285,15 @@ async fn validate_host_file_system_is_populated() { let read_env_path = CAFE_DATA_PATH.read().await; _ = HOST_FILE_SYSTEM.get_or_init(|| { if !read_env_path.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cafe_root_path_required", - cause = "Could not find the cafe path for the root filesystem", - suggestions = valuable(&[ - "You can specify the path manually with an environment variable: [`CAFE_ROOT`]", - "You can specify the path manually with a cli argument: [`--cafe-dir`]", - "You can file an issue to get us to auto-detect the best path for your OS.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not find the cafe path for the root filesystem!"), - [ - miette!( - "You can specify the path to the directory with the environment variable `CAFE_ROOT`" - ), - miette!( - "You can specify the path to the directory with the cli argument `--cafe-dir`" - ), - miette!( - "You can file an issue with the project to choose a default directory for your OS." - ), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::cafe_root_path_required", + help = valuable(&[ + "You can specify the path manually with an environment variable: [`CAFE_ROOT`]", + "You can specify the path manually with a cli argument: [`--cafe-dir`]", + "You can file an issue to get us to auto-detect the best path for your OS.", + ]), + "Could not find the cafe path for the root filesystem", + ); std::process::exit(ARGV_NO_CAFE_ROOT); } @@ -428,26 +310,12 @@ async fn validate_host_file_system_is_populated() { state } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::cannot_load_host_filesystem", - ?cause, - cafe_root_path = %cafe_root_path.display(), - "failed to load host filesystem path", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "Host Filesystem Path is located at: {}", - cafe_root_path.display(), - ), - "Cannot load cafe root host filesystem!", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::argv::cannot_load_host_filesystem", + ?cause, + cafe_root_path = %cafe_root_path.display(), + "failed to load host filesystem path", + ); std::process::exit(ARGV_CAFE_ROOT_LOAD_FAILURE); } diff --git a/cmd/bridgectl/src/commands/argv_helpers/serial.rs b/cmd/bridgectl/src/commands/argv_helpers/serial.rs index 5642db6..abd6df6 100644 --- a/cmd/bridgectl/src/commands/argv_helpers/serial.rs +++ b/cmd/bridgectl/src/commands/argv_helpers/serial.rs @@ -1,14 +1,11 @@ use crate::{ - SHOULD_LOG_JSON, exit_codes::{ ARGV_SERIAL_CONFLICTING_ARGUMENTS, SERIAL_PORT_CONNECTION_FAILURE, SHOULD_NEVER_HAPPEN_FAILURE, }, knobs::{cli::SharedSerialPortFlags, env::BRIDGECTL_SERIAL_PORT}, - utils::add_context_to, }; use cat_dev::serial::{AsyncSerialPort, SerialLines}; -use miette::miette; use std::{path::PathBuf, time::Duration}; use tokio::{ io::{AsyncBufRead, BufReader}, @@ -67,34 +64,15 @@ pub async fn coalesce_serial_ports( ) -> SerialLogger { let arg_to_take = if serial_port_flags.serial_port_flag().is_some() && serial_port_positional.is_some() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::conflicting_serial_port_args", - flags.serial_port = valuable(&serial_port_flags), - args.serial_port = ?serial_port_positional, - suggestions = valuable(&[ - "You only need to specify a serial port in one way, either through an argument, or a flag.", - "There is no such thing as multiple serial ports for the cat-dev.", - ]), - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Positional argument conflicts with flag arguments!"), - [ - miette!( - "You only need to specify a serial port in one way, either through an argument, or a flag." - ), - miette!( - help = format!("Serial Port Flags: {serial_port_flags}"), - "A CAT-DEV does not support multiple serial ports at the same time.", - ), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::conflicting_serial_port_args", + flags.serial_port = valuable(&serial_port_flags), + args.serial_port = ?serial_port_positional, + help = valuable(&[ + "You only need to specify a serial port in one way, either through an argument, or a flag.", + "There is no such thing as multiple serial ports for the cat-dev.", + ]), + ); std::process::exit(ARGV_SERIAL_CONFLICTING_ARGUMENTS); } else if let Some(flag) = serial_port_flags.serial_port_flag() { @@ -110,33 +88,13 @@ pub async fn coalesce_serial_ports( let port = match AsyncSerialPort::new(arg_to_take) { Ok(port) => port, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::argv::serial_connection_failure", - ?cause, - help = "Please file an issue if it's not clear with your serial device.", - port = %arg_to_take.display(), - "failed to connect to serial device specified" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("{cause:?}"), - [ - miette!("Failed to connect to specified serial device."), - miette!( - help = format!( - "Specified serial device is: {}", - arg_to_take.display() - ), - "Please file an issue if it's not clear why your OS is giving us an error.", - ), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::argv::serial_connection_failure", + ?cause, + help = "Please file an issue if it's not clear with your serial device.", + port = %arg_to_take.display(), + "failed to connect to serial device specified" + ); std::process::exit(SERIAL_PORT_CONNECTION_FAILURE); } @@ -194,16 +152,10 @@ impl SerialLogger { tokio::select! { () = sleep(Duration::from_secs(u64::MAX)) => {} _ = ctrl_c_signal() => { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::serial::honk_shoo_detected_ctrlc", - "ctrl-c has been hit, shutting down empty serial logger!", - ); - } else { - info!( - "Ctrl-C has been detected as being hit! Shutting down empty serial logger!" - ); - } + info!( + id = "bridgectl::serial::honk_shoo_detected_ctrlc", + "ctrl-c has been hit, shutting down empty serial logger!", + ); break; } @@ -212,18 +164,11 @@ impl SerialLogger { }) { Ok(port) => port, Err(cause) => { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::serial::debug_out_watcher_spawn_failure", - ?cause, - "failed to spawn task to watch serial logs; internal", - ); - } else { - warn!( - ?cause, - "internal error: failed to spawn task to watch for debug out serial logs, serial logs will not be watched for.", - ); - } + warn!( + id = "bridgectl::serial::debug_out_watcher_spawn_failure", + ?cause, + "failed to spawn task to watch serial logs; internal", + ); std::process::exit(SHOULD_NEVER_HAPPEN_FAILURE); } @@ -245,18 +190,11 @@ impl SerialLogger { }) { Ok(port) => port, Err(cause) => { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::serial::watcher_spawn_failure", - ?cause, - "failed to spawn task to watch serial logs; internal", - ); - } else { - warn!( - ?cause, - "internal error: failed to spawn task to watch for serial logs, serial logs will not be watched for.", - ); - } + warn!( + id = "bridgectl::serial::watcher_spawn_failure", + ?cause, + "failed to spawn task to watch serial logs; internal", + ); std::process::exit(SHOULD_NEVER_HAPPEN_FAILURE); } @@ -272,59 +210,36 @@ impl SerialLogger { tokio::select! { res = reader.next_line() => { match res { - Ok(Some(line)) => if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::serial_log::watcher::line", - %line, - "received log line from serial port", - ); - } else { - info!(line); - } + Ok(Some(line)) => info!( + id = "bridgectl::serial_log::watcher::line", + line, + ), Ok(None) => { - if SHOULD_LOG_JSON() { - debug!( - id = "bridgectl::serial_log::watcher::graceful_shutdown", - shutdown_reason = "empty-receive", - "shutting down gracefully" - ); - } else { - debug!( - shutdown_reason = "empty-receive", - "shutting down serial log watcher gracefully..." - ); - } + debug!( + id = "bridgectl::serial_log::watcher::graceful_shutdown", + shutdown_reason = "empty-receive", + "shutting down gracefully" + ); break; } Err(cause) => { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::serial_log::watcher::failure", - ?cause, - "could not receive lines from this serial port." - ); - } else { - warn!(?cause, "serial port gave us an error trying to read from it."); - } + warn!( + id = "bridgectl::serial_log::watcher::failure", + ?cause, + "could not receive lines from this serial port." + ); break; } } } _ = ctrl_c_signal() => { - if SHOULD_LOG_JSON() { - debug!( - id = "bridgectl::serial_log::watcher::graceful_shutdown", - shutdown_reason = "ctrl-c", - "shutting down gracefully" - ); - } else { - debug!( - shutdown_reason = "ctrl-c", - "shutting down serial log watcher gracefully..." - ); - } + debug!( + id = "bridgectl::serial_log::watcher::graceful_shutdown", + shutdown_reason = "ctrl-c", + "shutting down gracefully" + ); break; } diff --git a/cmd/bridgectl/src/commands/boot/atapi.rs b/cmd/bridgectl/src/commands/boot/atapi.rs index 958fe8c..90eea44 100644 --- a/cmd/bridgectl/src/commands/boot/atapi.rs +++ b/cmd/bridgectl/src/commands/boot/atapi.rs @@ -5,10 +5,8 @@ //! communications over a similar sata protocol. use crate::{ - SHOULD_LOG_JSON, exit_codes::{BOOT_COULD_NOT_CONNECT, BOOT_COULD_NOT_SPAWN}, knobs::env::ATAPI_OVERRIDE_LOAD_BEARING_SLEEP_MS, - utils::add_context_to, }; use cat_dev::{ fsemul::{ @@ -17,7 +15,6 @@ use cat_dev::{ }, net::server::TCPServer, }; -use miette::miette; use std::net::Ipv4Addr; use tokio::{signal::ctrl_c as ctrl_c_signal, task::Builder as TaskBuilder}; use tracing::{error, info}; @@ -48,21 +45,11 @@ pub async fn serve_atapi( { Ok(srv) => srv, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::atapi_bind_failure", - ?cause, - "failed to start server for ATAPI Emulation" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to start server for ATAPI Emulation"), - [cause.into()].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::atapi_bind_failure", + ?cause, + "failed to start server for ATAPI Emulation" + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -79,50 +66,26 @@ fn spawn_atapi(atapi_emulator: TCPServer) { tokio::select! { res = atapi_emulator.bind() => { if let Err(cause) = res { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::atapi_spawn_failure", - ?cause, - "failed to bind server to serve data to MION" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to bind server to serve ATAPI data to MION!"), - [miette!("{cause:?}")].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::atapi_spawn_failure", + ?cause, + "failed to bind server to serve data to MION" + ); } }, - _ = ctrl_c_signal() => if SHOULD_LOG_JSON() { + _ = ctrl_c_signal() => { info!( id = "bridgectl::boot::atapi_detected_ctrlc", "ctrl-c has been hit, shutting down atapi", ); - } else { - info!( - "Ctrl-C has been detected as being hit! Shutting down atapi!" - ); } } }) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::atapi_spawn_failure", - ?cause, - "failed to spawn task to serve atapi data to mion" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to spawn task to serve ATAPI data to MION!"), - [miette!("{cause:?}")].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::atapi_spawn_failure", + ?cause, + "failed to spawn task to serve atapi data to mion" + ); std::process::exit(BOOT_COULD_NOT_SPAWN); } diff --git a/cmd/bridgectl/src/commands/boot/mod.rs b/cmd/bridgectl/src/commands/boot/mod.rs index 2e27cce..f5b6bcc 100644 --- a/cmd/bridgectl/src/commands/boot/mod.rs +++ b/cmd/bridgectl/src/commands/boot/mod.rs @@ -50,7 +50,6 @@ mod sdio; mod utils; use crate::{ - SHOULD_LOG_JSON, commands::{ argv_helpers::{ coalesce_serial_ports, get_atapi_port, get_host_bind_address, get_pcfs_sata_port, @@ -82,7 +81,6 @@ use cat_dev::mion::{ cgis::{power_on, power_on_v2}, proto::cgis::SetupParameters, }; -use miette::miette; use std::{net::Ipv4Addr, path::PathBuf}; use tokio::task::JoinHandle; use tracing::{error, field::valuable, info, warn}; @@ -207,49 +205,39 @@ async fn boot_modern_without_pcfs( serial_handle: JoinHandle<()>, ) { if needs_pcfs { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::boot::override_pcfs", - reason = "manually_requested", - "overriding PCFS boot mode, the cat-dev will still have an error light but should at least boot to SystemConfigTool", - ); - } else { - warn!( - reason = "manually_requested", - "Overriding PCFS boot mode, the cat-dev will still have an error light but should at least boot to SystemConfigTool", - ); - } + warn!( + id = "bridgectl::boot::override_pcfs", + reason = "manually_requested", + "overriding PCFS boot mode, the cat-dev will still have an error light but should at least boot to SystemConfigTool", + ); } match power_on_v2(bridge_ip, host_ip, None, None, false).await { Ok(result_code) => { if result_code { - info!("Successfully powered on MION!"); + info!( + id = "bridgectl::boot::power_on_v2", + "Successfully powered on MION!", + ); _ = serial_handle.await; } else { - error!("Failed to boot cat-dev bridge! Please reach out for support!"); + error!( + id = "bridgectl::boot::power_on_v2_failure", + "Failed to boot cat-dev bridge! Please reach out for support!", + ); std::process::exit(BOOT_CGI_FAILURE); } } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::failed_to_boot_device", - bridge.ip = %bridge_ip, - ?cause, - suggestions = valuable(&[ - "Please file an issue, and reach out!" - ]), - ); - } else { - error!( - "\n{:?}", - miette!( - help = "PLEASE PLEASE PLEASE FILE AN ISSUE!", - "Failure to perform non PCFS boot!!! THIS IS STILL EARLY !!! PLEASE FILE AN ISSUE!\n {cause:?}", - ), - ); - } + error!( + id = "bridgectl::boot::failed_to_boot_device", + bridge.ip = %bridge_ip, + ?cause, + help = valuable(&[ + "Please file an issue, and reach out!" + ]), + "Failed to call power_on_v2 api!", + ); std::process::exit(BOOT_CGI_FAILURE); } @@ -266,32 +254,29 @@ async fn boot_legacy_without_pcfs(bridge_ip: Ipv4Addr, serial_handle: JoinHandle match power_on(bridge_ip).await { Ok(result_code) => { if result_code { - info!("Successfully powered on MION!"); + info!( + id = "bridgectl::boot::power_on", + "Successfully powered on MION!", + ); _ = serial_handle.await; } else { - error!("Failed to boot cat-dev bridge! Please reach out for support!"); + error!( + id = "bridgectl::boot::power_on_failure", + "Failed to boot cat-dev bridge! Please reach out for support!", + ); std::process::exit(BOOT_CGI_FAILURE); } } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::legacy::failed_to_boot_device", - bridge.ip = %bridge_ip, - ?cause, - suggestions = valuable(&[ - "Please file an issue, and reach out!" - ]), - ); - } else { - error!( - "\n{:?}", - miette!( - help = "PLEASE PLEASE PLEASE FILE AN ISSUE!", - "Failure to perform non PCFS boot!!! THIS IS STILL EARLY !!! PLEASE FILE AN ISSUE!\n {cause:?}", - ), - ); - } + error!( + id = "bridgectl::boot::legacy::failed_to_boot_device", + bridge.ip = %bridge_ip, + ?cause, + help = valuable(&[ + "Please file an issue, and reach out!" + ]), + "Failed to call power_on api!", + ); std::process::exit(BOOT_CGI_FAILURE); } @@ -307,16 +292,12 @@ fn get_will_use_sata(disable_sata_cli: bool) -> bool { }; if !result { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::boot::disabled_sata_port", - notes = valuable(&[ - "All File I/O Operations should be expected to be slower, and not as performant.", - ]), - ); - } else { - warn!("The SATA server was disabled, all file operations will be noticeably slower."); - } + warn!( + id = "bridgectl::boot::disabled_sata_port", + notes = valuable(&[ + "All File I/O Operations should be expected to be slower, and not as performant.", + ]), + ); } result diff --git a/cmd/bridgectl/src/commands/boot/sata.rs b/cmd/bridgectl/src/commands/boot/sata.rs index ae3b9d2..a329d2d 100644 --- a/cmd/bridgectl/src/commands/boot/sata.rs +++ b/cmd/bridgectl/src/commands/boot/sata.rs @@ -5,10 +5,8 @@ //! level emulation. use crate::{ - SHOULD_LOG_JSON, exit_codes::{BOOT_COULD_NOT_CONNECT, BOOT_COULD_NOT_SPAWN}, knobs::env::PCFS_OVERRIDE_LOAD_BEARING_SLEEP_MS, - utils::add_context_to, }; use cat_dev::{ fsemul::{ @@ -17,7 +15,6 @@ use cat_dev::{ }, net::server::TCPServer, }; -use miette::miette; use std::{net::Ipv4Addr, path::PathBuf}; use tokio::{signal::ctrl_c as ctrl_c_signal, task::Builder as TaskBuilder}; use tracing::{error, info}; @@ -57,21 +54,11 @@ pub async fn serve_sata( { Ok(srv) => srv, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::sata_bind_failure", - ?cause, - "failed to start server for PCFS Sata Emulation" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to start server for PCFS Sata Emulation"), - [cause.into()].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::sata_bind_failure", + ?cause, + "failed to start server for PCFS Sata Emulation" + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -88,33 +75,19 @@ fn spawn_sata(sata_emulator: TCPServer) { .spawn(async move { tokio::select! { _res = sata_emulator.bind() => {} - _ = ctrl_c_signal() => if SHOULD_LOG_JSON() { + _ = ctrl_c_signal() => { info!( id = "bridgectl::boot::sata_detected_ctrlc", "ctrl-c has been hit, shutting down PCFS over sata", ); - } else { - info!( - "Ctrl-C has been detected as being hit! Shutting down sata!" - ); } } }) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::pcfs_sata_spawn_failure", - ?cause, - "failed to spawn task to serve pcfs sata data to mion" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to spawn task to serve PCFS Sata data to MION!"), - [miette!("{cause:?}")].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::pcfs_sata_spawn_failure", + ?cause, + "failed to spawn task to serve pcfs sata data to mion" + ); std::process::exit(BOOT_COULD_NOT_SPAWN); } diff --git a/cmd/bridgectl/src/commands/boot/sdio.rs b/cmd/bridgectl/src/commands/boot/sdio.rs index cee5017..cf41b61 100644 --- a/cmd/bridgectl/src/commands/boot/sdio.rs +++ b/cmd/bridgectl/src/commands/boot/sdio.rs @@ -4,10 +4,8 @@ //! is one way to transfer files/blocks form the PC to the filesystem. use crate::{ - SHOULD_LOG_JSON, exit_codes::{BOOT_COULD_NOT_CONNECT, BOOT_COULD_NOT_SPAWN, BOOT_FSEMUL_SERVER_ERROR}, knobs::env::SDIO_OVERRIDE_LOAD_BEARING_SLEEP_MS, - utils::add_context_to, }; use cat_dev::{ fsemul::{ @@ -17,7 +15,6 @@ use cat_dev::{ mion::proto::cgis::SetupParameters, net::server::TCPServer, }; -use miette::miette; use std::net::Ipv4Addr; use tokio::{signal::ctrl_c as ctrl_c_signal, task::Builder as TaskBuilder}; use tracing::{error, field::valuable, info}; @@ -61,34 +58,15 @@ pub async fn serve_sdio( { Ok(client) => client, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::sdio_connection_failure", - ?cause, - help = valuable(&[ - "Please ensure the device is running, and has no error lights on.", - "A reboot of the cat-dev device, and letting it settle may fix this.", - ]), - "failed to connect to cat-dev to serve sdio data" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to connect to cat-dev to serve data over SDIO"), - [ - miette!( - "Please ensure the device is running and has no error lights on." - ), - miette!( - "A reboot of the cat-dev device, and letting it settle may fix this." - ), - cause.into(), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::sdio_connection_failure", + ?cause, + help = valuable(&[ + "Please ensure the device is running, and has no error lights on.", + "A reboot of the cat-dev device, and letting it settle may fix this.", + ]), + "failed to connect to cat-dev to serve sdio data" + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -100,70 +78,43 @@ pub async fn serve_sdio( /// Actually spawn the background task that will process incoming requests, /// responses from the SDIO ports of MION communication. fn spawn_sdio_task(sdio_client: TCPServer) { - if let Err(cause) = TaskBuilder::new().name("bridgectl::boot::serve_sdio").spawn(async move { - tokio::select! { - result = sdio_client.connect() => { - if let Err(cause) = result { - if SHOULD_LOG_JSON() { + if let Err(cause) = TaskBuilder::new() + .name("bridgectl::boot::serve_sdio") + .spawn(async move { + tokio::select! { + result = sdio_client.connect() => { + if let Err(cause) = result { error!( id = "bridgectl::boot::sdio_failed_to_serve", ?cause, "failed serving sdio data to mion for pcfs", ); + + std::process::exit(BOOT_FSEMUL_SERVER_ERROR); } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed serving SDIO data to MION for PCFS"), - [ - miette!("This may mean the error light will start flashing/boot will fail because we cannot serve the proper data to your device."), - cause.into(), - ].into_iter(), - ), + info!( + id = "bridgectl::boot::sdio_exited_gracefully", + "SDIO has gracefully requested termination.", ); } - - std::process::exit(BOOT_FSEMUL_SERVER_ERROR); - } else if SHOULD_LOG_JSON() { + } + _ = ctrl_c_signal() => { info!( - id = "bridgectl::boot::sdio_exited_gracefully", - "SDIO has gracefully requested termination.", + id = "bridgectl::boot::sdio_detected_ctrlc", + "ctrl-c has been hit, shutting down sdio", ); - } else { - info!("Shutting down SDIO gracefully"); } } - _ = ctrl_c_signal() => if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::boot::sdio_detected_ctrlc", - "ctrl-c has been hit, shutting down sdio", - ); - } else { - info!( - "Ctrl-C has been detected as being hit! Shutting down SDIO!" - ); - } - } - }) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::sdio_spawn_failure", - ?cause, - "failed to spawn task to serve sdio data to mion" - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to spawn task to serve SDIO data to MION!"), - [ - miette!("Please ensure another copy of this program isn't running!"), - miette!("Please ensure you have enough resources to handle this server!"), - miette!("{cause:?}"), - ].into_iter(), - ), - ); - } + }) { + error!( + id = "bridgectl::boot::sdio_spawn_failure", + ?cause, + help = valuable(&[ + "Please ensure another copy of this program isn't running!", + "Please ensure you have enough resources to handle this server!", + ]), + "failed to spawn task to serve sdio data to mion" + ); std::process::exit(BOOT_COULD_NOT_SPAWN); } diff --git a/cmd/bridgectl/src/commands/boot/utils.rs b/cmd/bridgectl/src/commands/boot/utils.rs index 14f01e5..2a2e3ad 100644 --- a/cmd/bridgectl/src/commands/boot/utils.rs +++ b/cmd/bridgectl/src/commands/boot/utils.rs @@ -1,13 +1,8 @@ //! Utilities that aren't directly related to booting, but help get info that //! can inform the booting process. -use crate::{ - SHOULD_LOG_JSON, - exit_codes::{ - BOOT_CGI_FAILURE, BOOT_COULD_NOT_CONNECT, BOOT_NOT_READY_TO_BOOT, - BRIDGE_TOO_OLD_FOR_FEATURE, - }, - utils::add_context_to, +use crate::exit_codes::{ + BOOT_CGI_FAILURE, BOOT_COULD_NOT_CONNECT, BOOT_NOT_READY_TO_BOOT, BRIDGE_TOO_OLD_FOR_FEATURE, }; use cat_dev::mion::{ cgis::{ @@ -18,7 +13,6 @@ use cat_dev::mion::{ }; use fnv::FnvHashMap; use mac_address::MacAddress; -use miette::miette; use std::{hash::BuildHasherDefault, net::Ipv4Addr}; use tracing::{debug, error, warn}; @@ -42,33 +36,20 @@ use tracing::{debug, error, warn}; /// versions from `http:///update.cgi`, either cause we didn't make /// a successful HTTP request, or it contained data we didn't understand. pub async fn is_modern_bridge(bridge_ip: Ipv4Addr) -> bool { - if SHOULD_LOG_JSON() { - debug!( - id = "bridgectl::boot::check_modern_bridge", - "Determining MION capabilities...", - ); - } else { - debug!("Determining MION capabilities..."); - } + debug!( + id = "bridgectl::boot::check_modern_bridge", + "Determining MION capabilities...", + ); let versions = match get_versions(bridge_ip).await { Ok(versions) => versions, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::failed_to_get_mion_version", - ?cause, - bridge.ip = %bridge_ip, - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not fetch the current MION FW version of the MION bridge."), - [cause.into(), miette!(format!("Bridge IP: {bridge_ip}"))].into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::failed_to_get_mion_version", + ?cause, + bridge.ip = %bridge_ip, + "Failed to get MION version!", + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -82,20 +63,12 @@ pub async fn is_modern_bridge(bridge_ip: Ipv4Addr) -> bool { || (mion_version[1] == 14 && mion_version[2] >= 77); if !is_modern { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::boot::old_mion_warning", - bridge.ip = %bridge_ip, - bridge.version = %versions.displayable_mion_version(), - "mion firmware outdated, please update to at least 0.00.14.77", - ); - } else { - warn!( - bridge.ip = %bridge_ip, - bridge.version = %versions.displayable_mion_version(), - "Your Cat-DEV's MION Board Version is rather old, and not fully functional. Please update it to at least 0.00.14.77 for full functionality...", - ); - } + warn!( + id = "bridgectl::boot::old_mion_warning", + bridge.ip = %bridge_ip, + bridge.version = %versions.displayable_mion_version(), + "Your Cat-DEV's MION Board Version is rather old, and not fully functional. Please update it to at least 0.00.14.77 for full functionality...", + ); } is_modern @@ -146,23 +119,11 @@ pub async fn validate_bridge_ready_for_booting( .unwrap_or_default() != "OK" { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::check_info_result", - response_fields = ?information_request, - "Result was not okay for receiving information", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "debugging note, all results from the cat-dev: {information_request:?}" - ), - "Fetching information was not successful", - ), - ); - } + error!( + id = "bridgectl::boot::check_info_result", + response_fields = ?information_request, + "Result was not okay for receiving information", + ); std::process::exit(BOOT_NOT_READY_TO_BOOT); } @@ -173,43 +134,22 @@ pub async fn validate_bridge_ready_for_booting( .unwrap_or_default() != "0.0.0.0" { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::boot::owned_by_other_host", - bridge.ip = %bridge_ip, - bridge.name = %bridge_name, - response_fields = ?information_request, - "MION is currently being managed by another host!!", - ); - } else { - warn!( + warn!( + id = "bridgectl::boot::owned_by_other_host", + bridge.ip = %bridge_ip, + bridge.name = %bridge_name, + response_fields = ?information_request, + "MION is currently being managed by another host!!", + ); + + if !will_take_over { + error!( + id = "bridgectl::boot::mion_already_owned", bridge.ip = %bridge_ip, bridge.name = %bridge_name, - "\n{:?}", - miette!( - help = format!( - "debugging note, all results from the cat-dev: {information_request:?}" - ), - "MION Bridge is currently being managed by another host!!", - ), + "Did not specify `--take-ownership`, exiting because MION is owned by another..." ); - } - if !will_take_over { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::mion_already_owned", - bridge.ip = %bridge_ip, - bridge.name = %bridge_name, - "Did not specify `--take-ownership`, exiting because MION is owned by another..." - ); - } else { - error!( - bridge.ip = %bridge_ip, - bridge.name = %bridge_name, - "Did not specify `--take-ownership`, exiting because MION is owned by another..." - ); - } std::process::exit(BOOT_NOT_READY_TO_BOOT); } } @@ -242,40 +182,22 @@ pub async fn turn_down_for_disc(bridge_ip: Ipv4Addr) { match set_disc_eject_state(bridge_ip, false).await { Ok(success) => { if !success { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::eject_failed", - bridge.ip = %bridge_ip, - "Bridge responded with an error (and no extra info) while ejecting the disc", - ); - } else { - error!( - bridge.ip = %bridge_ip, - "Bridge responded with an error (and no extra info) while ejecting the disc", - ); - } + error!( + id = "bridgectl::boot::eject_failed", + bridge.ip = %bridge_ip, + "Bridge responded with an error (and no extra info) while ejecting the disc", + ); std::process::exit(BOOT_NOT_READY_TO_BOOT); } } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::cannot_eject_disc", - ?cause, - bridge.ip = %bridge_ip, - "cannot eject disc to properly boot bridge", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!("while talking to bridge: {bridge_ip}"), - "Could not eject disc from MION to then properly boot MION" - ) - .wrap_err(cause) - ); - } + error!( + id = "bridgectl::boot::cannot_eject_disc", + ?cause, + bridge.ip = %bridge_ip, + "cannot eject disc to properly boot bridge", + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -310,52 +232,16 @@ pub async fn wrap_power_on( }; if let Err(cause) = res { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::send_power_on", - ?cause, - bridge.ip = %bridge_ip, - bridge.is_modern = is_modern_bridge, - host.ip_override = ?host_ip, - host.atapi_port = %final_atapi_port, - host.sata_port = ?final_sata_port, - "Failed to power on bridge!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Could not power on bridge!"), - [ - cause.into(), - miette!( - help = format!( - "Arguments were: Bridge IP: {bridge_ip} {modern_str}", - modern_str = if is_modern_bridge { "(modern)" } else { "" }, - ), - "Bridge Information Retrieved", - ), - miette!( - help = format!( - "Arguments were: Host IP Override: {} / ATAPI: {final_atapi_port} / SATA: {}", - if let Some(over) = host_ip { - format!("{over}") - } else { - "(None)".to_owned() - }, - if let Some(sp) = final_sata_port { - format!("{sp}") - } else { - "(Not Enabled)".to_owned() - }, - ), - "Host Information", - ), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::boot::send_power_on", + ?cause, + bridge.ip = %bridge_ip, + bridge.is_modern = is_modern_bridge, + host.ip_override = ?host_ip, + host.atapi_port = %final_atapi_port, + host.sata_port = ?final_sata_port, + "Failed to power on bridge!", + ); std::process::exit(BOOT_CGI_FAILURE); } @@ -378,16 +264,10 @@ async fn validate_legacy_bridge_ready_for_booting( parameter_space_port: Option, ) -> (FnvHashMap, Option, bool) { if will_take_over { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::take_over_unsupported", - "you specified `--take-ownership` which is not supported for MIONs running this old of FW..." - ); - } else { - error!( - "You have specified `--take-ownership` which is not supported on the FW version your MION is running..." - ); - } + error!( + id = "bridgectl::boot::take_over_unsupported", + "you specified `--take-ownership` which is not supported for MIONs running this old of FW..." + ); std::process::exit(BRIDGE_TOO_OLD_FOR_FEATURE); } @@ -398,24 +278,13 @@ async fn validate_legacy_bridge_ready_for_booting( match get_param_space_parameters(bridge_ip, parameter_space_port, None).await { Ok(ps) => ps, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::failed_dump_mion_param_space", - ?cause, - bridge.ip = %bridge_ip, - bridge.override_ps_port = ?parameter_space_port, - "Failed to get boot mode for legacy MION of parameter space port.", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!("while talking to bridge: {bridge_ip}"), - "Failed to get boot mode for legacy MION of parameter space port." - ) - .wrap_err(cause) - ); - } + error!( + id = "bridgectl::boot::failed_dump_mion_param_space", + ?cause, + bridge.ip = %bridge_ip, + bridge.override_ps_port = ?parameter_space_port, + "Failed to get boot mode for legacy MION of parameter space port.", + ); std::process::exit(BOOT_COULD_NOT_CONNECT); } @@ -444,21 +313,14 @@ async fn get_info_and_parameters( let information_request = match get_info(bridge_ip, bridge_name).await { Ok(map) => map, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::get_bridge_info", - ?cause, - "failed to query bridge information to make sure it was ready for booting", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!("You can ensure the bridge is ready to be viewed at: "), - "Failed to query bridge information to make sure it was ready for booting, please make sure the device is on, and has it's webpages running." - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::boot::get_bridge_info", + ?cause, + help = format!( + "You can ensure the bridge is ready to be viewed at: " + ), + "failed to query bridge information to make sure it was ready for booting", + ); std::process::exit(BOOT_CGI_FAILURE); } @@ -485,21 +347,12 @@ async fn wrap_get_setup_parameters( match get_setup_parameters(bridge_ip).await { Ok(params) => Some(params), Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::boot::get_setup_parameters", - ?cause, - "failed to query setup parameters to make sure the bridge was ready for booting", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!("You can see the setup page at: "), - "Failed to query setup information to make sure it was ready for booting, please make sure that the device is on, and has it's webpages running.", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::boot::get_setup_parameters", + ?cause, + help = format!("You can see the setup page at: "), + "failed to query setup parameters to make sure the bridge was ready for booting", + ); if let Some(mac) = default_mac { warn!("Using default setup-parameters, may be incorrect"); diff --git a/cmd/bridgectl/src/commands/dump_parameters.rs b/cmd/bridgectl/src/commands/dump_parameters.rs index f8e60f9..4b10b00 100644 --- a/cmd/bridgectl/src/commands/dump_parameters.rs +++ b/cmd/bridgectl/src/commands/dump_parameters.rs @@ -1,54 +1,35 @@ use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::get_targeted_bridge_ip, - exit_codes::DUMP_PARAMS_FAILED_TO_GET_PARAMS, + commands::argv_helpers::get_targeted_bridge_ip, exit_codes::DUMP_PARAMS_FAILED_TO_GET_PARAMS, }; use cat_dev::mion::{parameter::get_parameters, proto::parameter::DumpedMionParameters}; -use miette::miette; -use std::net::Ipv4Addr; +use std::{fmt::Write, net::Ipv4Addr}; use tracing::{error, info}; /// Actual command handler for the `dump-parameters`, or `dp` command. pub async fn handle_dump_parameters(parameter_space_port: Option) { let parameters = fetch_parameters(get_targeted_bridge_ip().await, parameter_space_port).await; - if !SHOULD_LOG_JSON() { - info!("\n\nDumping Parameter Space:"); - } + info!( + id = "bridgectl::dump_parameters::header", + "Dumping Parameter Space:" + ); for (chunk_idx, chunk) in parameters.get_raw_parameters().chunks(16).enumerate() { - if SHOULD_LOG_JSON() { - let mut ascii_str = String::with_capacity(16); - let mut bytes = Vec::with_capacity(16); - - for byte in chunk { - bytes.push(byte); - let as_char = *byte as char; - if as_char.is_ascii_alphanumeric() { - ascii_str.push(as_char); - } else { - ascii_str.push('.'); - } - } - - info!( - id = "bridgectl::dump_parameters::dump_line", - %ascii_str, - ?bytes, - ); - } else { - print!(" {chunk_idx:02x}0: "); - let mut ascii_str = String::with_capacity(16); - for byte in chunk { - print!("{byte:02x} "); - let as_char = *byte as char; - if as_char.is_ascii_alphanumeric() { - ascii_str.push(as_char); - } else { - ascii_str.push('.'); - } + let mut line = String::new(); + _ = write!(&mut line, " {chunk_idx:02x}0: "); + let mut ascii_str = String::with_capacity(16); + for byte in chunk { + _ = write!(&mut line, "{byte:02x} "); + let as_char = *byte as char; + if as_char.is_ascii_alphanumeric() { + ascii_str.push(as_char); + } else { + ascii_str.push('.'); } - println!(" {ascii_str}"); } + _ = write!(&mut line, " {ascii_str}"); + + info!(id = "bridgectl::dump_parameters::dump_line", line,); } } @@ -56,22 +37,12 @@ async fn fetch_parameters(bridge_ip: Ipv4Addr, bridge_port: Option) -> Dump match get_parameters(bridge_ip, bridge_port, None).await { Ok(params) => params, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::dump_parameters::failed_to_execute_dump_parameters", - ?cause, - help = "We could not send/receive a packet to your MION to ask for it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "If you leave a MION running for too long it may stop responding to parameter requests.", - "Could not send/receive a packet to your MION to ask for it's parameters, please ensure the device is running.", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::dump_parameters::failed_to_execute_dump_parameters", + ?cause, + help = "We could not send/receive a packet to your MION to ask for it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", + ); + std::process::exit(DUMP_PARAMS_FAILED_TO_GET_PARAMS); } } diff --git a/cmd/bridgectl/src/commands/get.rs b/cmd/bridgectl/src/commands/get.rs index 650ce66..f1062df 100644 --- a/cmd/bridgectl/src/commands/get.rs +++ b/cmd/bridgectl/src/commands/get.rs @@ -1,21 +1,21 @@ //! Handles fetching the information for just one particular bridge. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{ get_control_port, get_padded_string, get_scan_timeout, get_targeted_bridge_ip, get_targeted_bridge_name, lease_bridge_config, }, exit_codes::{GET_FAILED_TO_FIND_SPECIFIC_DEVICE, GET_FAILED_TO_SEARCH_FOR_DEVICE}, - utils::add_context_to, }; use cat_dev::mion::{ discovery::{MIONFindBy, find_mion}, proto::control::MionIdentity, }; -use miette::miette; -use std::net::Ipv4Addr; -use terminal_size::{Width as TermWidth, terminal_size}; +use rm_lisa::display::SuperConsole; +use std::{ + io::{Stderr, Stdout}, + net::Ipv4Addr, +}; use tracing::{debug, error, field::valuable, info, warn}; const FALLBACK_HEADER: &str = "Bridge Name | IP Address | Is Default"; @@ -27,19 +27,11 @@ const DETAILED_HEADER_LINE: &str = "-------------------------------------------- /// Actual command handler for the `get` command. pub async fn handle_get(use_table: bool) { let bridge_ip = get_targeted_bridge_ip().await; - - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::get::looking_up_detailed_bridge_info", - %bridge_ip, - "looking up detailed bridge information...", - ); - } else { - info!( - %bridge_ip, - "Looking up detailed bridge information...", - ); - } + info!( + id = "bridgectl::get::looking_up_detailed_bridge_info", + %bridge_ip, + "looking up detailed bridge information...", + ); let mion_identity_opt = match find_mion( MIONFindBy::Ip(bridge_ip), @@ -51,21 +43,11 @@ pub async fn handle_get(use_table: bool) { { Ok(opt) => opt, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get::failed_to_execute_broadcast", - ?cause, - help = "Could not setup sockets to broadcast and search for all MIONs; perhaps another program is already using the single MION port? Trying to find MION from config file (will be less detailed).", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not setup sockets to broadcast and search for a MION (trying to search config file, will be less detailed).", - ).wrap_err(cause), - ); - } + error!( + id = "bridgectl::get::failed_to_execute_broadcast", + ?cause, + help = "Could not setup sockets to broadcast and search for all MIONs; perhaps another program is already using the single MION port? Trying to find MION from config file (will be less detailed).", + ); fallback_to_config_file(use_table, GET_FAILED_TO_SEARCH_FOR_DEVICE).await; // Async ! isn't stable and recognized :( @@ -74,41 +56,20 @@ pub async fn handle_get(use_table: bool) { }; let Some(identity) = mion_identity_opt else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get::get_failed_to_find_a_device", - suggestions = valuable(&[ - "Please ensure the CAT-DEV you're trying to find is powered on, and running.", - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", - "Ensure your filters line up with a single CAT-DEV device.", - ]), - help = "Is attempting to fallback to a config file (will be less detailed).", - ); - - fallback_to_config_file(use_table, GET_FAILED_TO_FIND_SPECIFIC_DEVICE).await; - // Async ! isn't stable and recognized :( - unreachable!() - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to find bridge that matched the series of filters -- falling back to config file (will be less detailed).", - ), - [ - miette!("Please ensure the CAT-DEV you're trying to find is powered on, and running."), - miette!("Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device."), - miette!("If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans."), - miette!("Ensure your filters line up with a single CAT-DEV device."), - ].into_iter(), - ), - ); + error!( + id = "bridgectl::get::get_failed_to_find_a_device", + suggestions = valuable(&[ + "Please ensure the CAT-DEV you're trying to find is powered on, and running.", + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.", + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.", + "Ensure your filters line up with a single CAT-DEV device.", + ]), + help = "Is attempting to fallback to a config file (will be less detailed).", + ); - fallback_to_config_file(use_table, GET_FAILED_TO_FIND_SPECIFIC_DEVICE).await; - // Async ! isn't stable and recognized :( - unreachable!() - } + fallback_to_config_file(use_table, GET_FAILED_TO_FIND_SPECIFIC_DEVICE).await; + // Async ! isn't stable and recognized :( + unreachable!() }; print_detailed_bridge(use_table, &identity); @@ -120,19 +81,11 @@ async fn fallback_to_config_file(use_table: bool, exit_code: i32) { let bridge_state = lease_bridge_config().await; if use_table { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::get::fallback_table_print", - line = FALLBACK_HEADER - ); - info!( - id = "bridgectl::get::fallback_table_print", - line = FALLBACK_HEADER_LINE - ); - } else { - println!("{FALLBACK_HEADER}"); - println!("{FALLBACK_HEADER_LINE}"); - } + info!(id = "bridgectl::get::fallback_table_print", FALLBACK_HEADER); + info!( + id = "bridgectl::get::fallback_table_print", + FALLBACK_HEADER_LINE + ); } let mut found_any = false; @@ -140,6 +93,7 @@ async fn fallback_to_config_file(use_table: bool, exit_code: i32) { debug!( id = "bridgectl::get::is_fallback_match", potential_bridge.name = bridge_name, + "fallback match check", ); if conf_bridge_name == bridge_name { @@ -158,15 +112,15 @@ async fn fallback_to_config_file(use_table: bool, exit_code: i32) { fn print_detailed_bridge(use_table: bool, bridge: &MionIdentity) { if use_table { - if let Some((TermWidth(characters_wide), _)) = terminal_size() { - if characters_wide < 150 { - warn!( - id = "bridgectl::get::terminal_may_be_small", - width.expected = 150, - width.was = characters_wide, - "!!! HEY! Your terminal width seems to be smaller than 150 characters! The table renders at ~150 characters, so we recommend making you terminal wider to see the table best !!!", - ); - } + if let Some(characters_wide) = SuperConsole::::terminal_width() + && characters_wide < 214 + { + warn!( + id = "bridgectl::get::terminal_may_be_small", + width.expected = 214, + width.was = characters_wide, + "!!! HEY! Your terminal width seems to be smaller than 214 characters! The table renders at ~150 characters, so we recommend making you terminal wider to see the table best !!!", + ); } let rendered_name = get_padded_string(bridge.name(), 30); @@ -196,30 +150,18 @@ fn print_detailed_bridge(use_table: bool, bridge: &MionIdentity) { "{rendered_name} | {rendered_ip} | {rendered_mac} | {rendered_fpga} | {rendered_fw} | {rendered_sdk} | {rendered_boot_mode} | {rendered_power_status}" ); - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::get::found_requested_bridge_network_table", - line = DETAILED_HEADER - ); - info!( - id = "bridgectl::get::found_requested_bridge_network_table", - line = DETAILED_HEADER_LINE - ); - info!( - id = "bridgectl::get::found_requested_bridge_network_table", - line = full_table_line, - bridge = valuable(bridge) - ); - } else { - println!("{DETAILED_HEADER}"); - println!("{DETAILED_HEADER_LINE}"); - println!("{full_table_line}"); - } - } else if SHOULD_LOG_JSON() { info!( - id = "bridgectl::get::found_requested_bridge_network", + id = "bridgectl::get::found_requested_bridge_network_table", + DETAILED_HEADER, + ); + info!( + id = "bridgectl::get::found_requested_bridge_network_table", + DETAILED_HEADER_LINE, + ); + info!( + id = "bridgectl::get::found_requested_bridge_network_table", bridge = valuable(bridge), - "Found the requested bridge on the network", + full_table_line, ); } else { info!( @@ -247,23 +189,12 @@ fn print_potential_bridge_match( let ip = get_padded_string(bridge_ip, 15); let line = format!("{name} | {ip} | {is_default}"); - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::get::potential_bridge_match_table", - line, - bridge.name = bridge_name, - bridge.ip = ?bridge_ip, - bridge.is_default = is_default, - ); - } else { - println!("{line}"); - } - } else if SHOULD_LOG_JSON() { info!( - id = "bridgectl::get::potential_bridge_match", + id = "bridgectl::get::potential_bridge_match_table", bridge.name = bridge_name, bridge.ip = ?bridge_ip, bridge.is_default = is_default, + line, ); } else { info!( @@ -276,19 +207,9 @@ fn print_potential_bridge_match( } fn print_no_fallback_found() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get::no_fallback_found", - suggestions = - valuable(&["Please ensure the bridge filters actually apply to a single bridge."]), - ); - } else { - error!( - "\n{:?}", - miette!( - help = "Please ensure the bridge filters actually apply to a single bridge.", - "Failed to find any bridge that matches your criteria in our configuration file.", - ), - ); - } + error!( + id = "bridgectl::get::no_fallback_found", + suggestions = + valuable(&["Please ensure the bridge filters actually apply to a single bridge."]), + ); } diff --git a/cmd/bridgectl/src/commands/get_parameters.rs b/cmd/bridgectl/src/commands/get_parameters.rs index 6704b2a..88de32a 100644 --- a/cmd/bridgectl/src/commands/get_parameters.rs +++ b/cmd/bridgectl/src/commands/get_parameters.rs @@ -1,11 +1,8 @@ use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::get_targeted_bridge_ip, exit_codes::{GET_PARAMS_FAILED_TO_GET_PARAMS, GET_PARAMS_NO_PARAMETERS_SPECIFIED}, - utils::add_context_to, }; use cat_dev::mion::{parameter::get_parameters, proto::parameter::DumpedMionParameters}; -use miette::miette; use std::net::Ipv4Addr; use tracing::{debug, error, field::valuable, info}; @@ -23,79 +20,51 @@ pub async fn handle_get_parameters( &fetch_parameters(bridge_ip, parameter_space_port).await, ); return; - } else if let Some(params) = bridge_or_params_arguments { - if !used_first_arg { - let bridge_ip = get_targeted_bridge_ip().await; - print_parameters( - ¶ms, - &fetch_parameters(bridge_ip, parameter_space_port).await, - ); - return; - } - } - - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get_params::no_params", - suggestions = valuable(&[ - "You can run `bridgectl get-params `, `bridgectl gp --default `, etc.", - "If running in a mochiato/cafe/cafex environment you can run: `bridgectl get-params `.", - "You can run `bridgectl get-params --help` to get more information.", - ]), - "No parameter arguments passed to `bridgectl get-params`, but we need a list of parameters to fetch!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("No parameter arguments passed to `bridgectl get-params`, but we need a list of parameters to fetch"), - [ - miette!("You can run `bridgectl get-params `, `bridgectl gp --default `, etc."), - miette!("If running in a mochiato/cafe/cafex environment you can run: `bridgectl get-params `."), - miette!("You can run `bridgectl get-params --help` to get more information on how to use this command."), - ].into_iter(), - ), + } else if let Some(params) = bridge_or_params_arguments + && !used_first_arg + { + let bridge_ip = get_targeted_bridge_ip().await; + print_parameters( + ¶ms, + &fetch_parameters(bridge_ip, parameter_space_port).await, ); + return; } + error!( + id = "bridgectl::get_params::no_params", + suggestions = valuable(&[ + "You can run `bridgectl get-params `, `bridgectl gp --default `, etc.", + "If running in a mochiato/cafe/cafex environment you can run: `bridgectl get-params `.", + "You can run `bridgectl get-params --help` to get more information.", + ]), + "No parameter arguments passed to `bridgectl get-params`, but we need a list of parameters to fetch!", + ); std::process::exit(GET_PARAMS_NO_PARAMETERS_SPECIFIED); } fn print_parameters(parameter_filters: &str, parameters: &DumpedMionParameters) { for filter in parameter_filters.split(',') { if filter.is_empty() { - if SHOULD_LOG_JSON() { - debug!( - id = "bridgectl::get_parameters::empty_parameter_filter", - line = "Filter in parameter filters was empty, continuing.", - ); - } else { - debug!("Filter in parameter filters was empty, continuing."); - } + debug!( + id = "bridgectl::get_parameters::empty_parameter_filter", + "Filter in parameter filters was empty, continuing.", + ); continue; } if let Ok(parameter_value) = parameters.get_parameter_by_name(filter) { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::get_parameters::parameter_found", - line="Found parameter!", - parameter.name=%filter, - parameter.value=%parameter_value, - ); - } else { - info!(parameter.name=%filter, parameter.value=%parameter_value, "Found your parameter!"); - } - } else if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get_parameters::parameter_not_found", - parameter.name = %filter, - line = "Could not find the parameter name, or index (0-511) with the name/index you specified. Please ensure you have typed it correctly.", + info!( + id = "bridgectl::get_parameters::parameter_found", + parameter.name=%filter, + parameter.value=%parameter_value, + "Found parameter!", ); } else { error!( + id = "bridgectl::get_parameters::parameter_not_found", parameter.name = %filter, - "Could not find the parameter name, or index (0-511) with the name/index you specified. Please ensure you have typed it correctly." + "Could not find the parameter name, or index (0-511) with the name/index you specified. Please ensure you have typed it correctly.", ); } } @@ -105,22 +74,12 @@ async fn fetch_parameters(bridge_ip: Ipv4Addr, bridge_port: Option) -> Dump match get_parameters(bridge_ip, bridge_port, None).await { Ok(params) => params, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::get_parameters::failed_to_execute_get_parameters", - ?cause, - help = "We could not send/receive a packet to your MION to ask for it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "If you leave a MION running for too long it may stop responding to parameter requests.", - "Could not send/receive a packet to your MION to ask for it's parameters, please ensure the device is running.", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::get_parameters::failed_to_execute_get_parameters", + ?cause, + help = "We could not send/receive a packet to your MION to ask for it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", + ); + std::process::exit(GET_PARAMS_FAILED_TO_GET_PARAMS); } } diff --git a/cmd/bridgectl/src/commands/help.rs b/cmd/bridgectl/src/commands/help.rs index dcaa0ed..badf9df 100644 --- a/cmd/bridgectl/src/commands/help.rs +++ b/cmd/bridgectl/src/commands/help.rs @@ -4,10 +4,7 @@ //! We have to handle `help` ourselves, as opposed to FULLY relying on [`clap`] //! so we can do things like printing the output in JSON. -use crate::{ - SHOULD_LOG_JSON, - knobs::cli::{CliArguments, Subcommands}, -}; +use crate::knobs::cli::{CliArguments, Subcommands}; use clap::{Arg, Command, CommandFactory}; use tracing::{field::valuable, info}; use valuable::Valuable; @@ -22,20 +19,6 @@ pub fn handle_help(opt_sub_command: Option) { let mut top_level_command = CliArguments::command(); let mut subcommands_as_command = Subcommands::command(); - if !SHOULD_LOG_JSON() { - if let Some(sub_command) = opt_sub_command { - let mut subcommands_as_command = Subcommands::command(); - let my_command = subcommands_as_command - .get_subcommands_mut() - .find(|potential_command| sub_command.name_matches(potential_command.get_name())) - .expect("internal error: recognized subcommand could not be matched on name?"); - info!("{}", my_command.render_long_help()); - } else { - info!("{}", top_level_command.render_long_help()); - } - return; - } - let (command, is_top_level) = if let Some(sub_command) = opt_sub_command { let my_command = subcommands_as_command .get_subcommands_mut() @@ -46,43 +29,50 @@ pub fn handle_help(opt_sub_command: Option) { (&mut top_level_command, true) }; - let args = command - .get_arguments() - .map(OwnedSubcommandOptionsHelpOutput::from) - .collect::>(); - let aliases = command - .get_all_aliases() - .map(ToOwned::to_owned) - .collect::>(); - let command_name = command.get_name().to_owned(); - let help = format!("{}", command.render_long_help()); - let options = command - .get_opts() - .map(OwnedSubcommandOptionsHelpOutput::from) - .collect::>(); - let positionals = command - .get_positionals() - .map(OwnedSubcommandOptionsHelpOutput::from) - .collect::>(); - let subcommands = command - .get_subcommands_mut() - .map(SubcommandHelpOutput::from) - .collect::>(); + if is_top_level { + info!( + id = "bridgectl::help::top_level", + lisa.force_combine_fields = true, + "{}", + top_level_command.render_long_help(), + ); + } else { + let args = command + .get_arguments() + .map(OwnedSubcommandOptionsHelpOutput::from) + .collect::>(); + let aliases = command + .get_all_aliases() + .map(ToOwned::to_owned) + .collect::>(); + let command_name = command.get_name().to_owned(); + let is_long_help = format!("{}", command.render_long_help()); + let options = command + .get_opts() + .map(OwnedSubcommandOptionsHelpOutput::from) + .collect::>(); + let positionals = command + .get_positionals() + .map(OwnedSubcommandOptionsHelpOutput::from) + .collect::>(); + let subcommands = command + .get_subcommands_mut() + .map(SubcommandHelpOutput::from) + .collect::>(); - info!( - id = if is_top_level { - "bridgectl::help::top_level".to_owned() - } else { - format!("bridgectl::help::{command_name}") - }, - help.args = valuable(&args), - help.aliases = valuable(&aliases), - help.display_help_text = help, - help.options = valuable(&options), - help.positionals = valuable(&positionals), - help.name = command_name, - help.sub_commands = valuable(&subcommands), - ); + info!( + id = format!("bridgectl::help::{command_name}"), + lisa.hide_fields_for_humans = true, + help.args = valuable(&args), + help.aliases = valuable(&aliases), + help.options = valuable(&options), + help.positionals = valuable(&positionals), + help.name = command_name, + help.sub_commands = valuable(&subcommands), + "{}", + is_long_help, + ); + } } #[derive(Debug, Valuable)] diff --git a/cmd/bridgectl/src/commands/list.rs b/cmd/bridgectl/src/commands/list.rs index 0f6d22e..6bafd8e 100644 --- a/cmd/bridgectl/src/commands/list.rs +++ b/cmd/bridgectl/src/commands/list.rs @@ -1,16 +1,14 @@ //! Handling listing all the bridges on the network, or cached bridges. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{ get_control_port, get_padded_string, get_scan_timeout, lease_bridge_config, }, exit_codes::LIST_COULD_NOT_SEARCH, - utils::add_context_to, }; use cat_dev::mion::{discovery::discover_bridges, proto::control::MionIdentity}; -use miette::miette; -use terminal_size::{Width as TermWidth, terminal_size}; +use rm_lisa::display::SuperConsole; +use std::io::{Stderr, Stdout}; use tokio::time::sleep; use tracing::{error, field::valuable, info, warn}; @@ -34,46 +32,28 @@ async fn list_from_network(use_table: bool) { let mut recv_channel = match discover_bridges(true, Some(get_control_port().await)).await { Ok(channel) => channel, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::list::failed_to_execute_broadcast", - ?cause, - help = "Could not setup sockets to broadcast and search for all MIONs; perhaps another program is already using the single MION port?", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "Perhaps another program is already using the single MION port?", - "Could not setup sockets to broadcast and search for all MIONs", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::list::failed_to_execute_broadcast", + ?cause, + help = "Could not setup sockets to broadcast and search for all MIONs; perhaps another program is already using the single MION port?", + ); std::process::exit(LIST_COULD_NOT_SEARCH); } }; - if use_table { - if let Some((TermWidth(characters_wide), _)) = terminal_size() { - if characters_wide < 150 { - warn!( - id = "bridgectl::list::terminal_may_be_small", - width.expected = 150, - width.was = characters_wide, - "!!! HEY! Your terminal width seems to be smaller than 150 characters! The table renders at ~150 characters, so we recommend making you terminal wider to see the table best !!!", - ); - } + if use_table && let Some(characters_wide) = SuperConsole::::terminal_width() { + if characters_wide < 214 { + warn!( + id = "bridgectl::list::terminal_may_be_small", + width.expected = 214, + width.was = characters_wide, + "!!! HEY! Your terminal width seems to be smaller than 214 characters! The table renders at ~150 characters, so we recommend making you terminal wider to see the table best !!!", + ); } - if SHOULD_LOG_JSON() { - info!(id = TABLE_TRACING_ID, line = TABLE_HEADER); - info!(id = TABLE_TRACING_ID, line = TABLE_HEADER_LINE); - } else { - println!("{TABLE_HEADER}"); - println!("{TABLE_HEADER_LINE}"); - } + info!(id = TABLE_TRACING_ID, line = TABLE_HEADER); + info!(id = TABLE_TRACING_ID, line = TABLE_HEADER_LINE); } let mut found_bridges = Vec::new(); @@ -132,20 +112,10 @@ fn print_detailed_bridge(bridge: &MionIdentity, use_table: bool) { let full_table_line = format!( "{rendered_name} | {rendered_ip} | {rendered_mac} | {rendered_fpga} | {rendered_fw} | {rendered_sdk} | {rendered_boot_mode} | {rendered_power_status}" ); - if SHOULD_LOG_JSON() { - info!( - id = TABLE_TRACING_ID, - line = full_table_line, - bridge = valuable(&bridge) - ); - } else { - println!("{full_table_line}"); - } - } else if SHOULD_LOG_JSON() { info!( - id = "bridgectl::list::discovered_bridge_over_network", + id = TABLE_TRACING_ID, bridge = valuable(&bridge), - "Found a bridge on the network", + full_table_line, ); } else { info!( @@ -163,49 +133,26 @@ fn print_detailed_bridge(bridge: &MionIdentity, use_table: bool) { } fn print_no_bridge_found_warning(was_early_exit: bool, early_timeout: Option) { - if SHOULD_LOG_JSON() { - let mut suggestions = vec![ - "Please ensure the CAT-DEV is powered on, and running.".to_owned(), - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.".to_owned(), - "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.".to_owned(), - ]; - if was_early_exit { - suggestions.push(format!( - "We stopped searching early, you can raise the time before we give up searching you can use the CLI Argument with `--early-timeout-seconds `, we timed out at {} seconds.", - early_timeout.unwrap_or(DEFAULT_EARLY_TIMEOUT), - )); - } - - warn!( - id = "bridgectl::list::failed_to_find_any_device", - suggestions = valuable(&suggestions), - "Could not find any bridges while broadcasting" - ); - } else { - let mut suggestions = vec![ - miette!("Please ensure the CAT-DEV is powered on, and running."), - miette!( - "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device." - ), - miette!( - "If you're not on the same VLAN, Subnet you can use something like: to forward between the two VLANs/Subnets." - ), - ]; - if was_early_exit { - suggestions.push(miette!(format!( - "We stopped searching early (at {}s), you can raise the time we stop searching early with the CLI Flag: `--early-timeout-seconds`.", - early_timeout.unwrap_or(DEFAULT_EARLY_TIMEOUT), - ))); - } - - warn!( - "\n{:?}", - add_context_to( - miette!("Could not find a bridge by the name, or potentially an ip."), - suggestions.into_iter(), - ), - ); + let mut suggestions = vec![ + "Please ensure the CAT-DEV is powered on, and running.".to_owned(), + "Make sure you are on the same Local Network, Subnet, and VLAN as the CAT-DEV device.".to_owned(), + "If you're not on the same VLAN, Subnet you can use something like: to forward between the subnets & vlans.".to_owned(), + ]; + if was_early_exit { + suggestions.push(format!( + "We stopped searching early, you can raise the time before we give up searching you can use the CLI Argument with `--early-timeout-seconds `, we timed out at {} seconds.", + early_timeout.unwrap_or(DEFAULT_EARLY_TIMEOUT), + )); } + + warn!( + id = "bridgectl::list::failed_to_find_any_device", + scan.was_early_exit = was_early_exit, + scan.timeout_value = ?early_timeout, + scan.timeout_unit = "seconds", + help = valuable(&suggestions), + "Could not find any bridges while broadcasting" + ); } /// List the bridges from a cache rather than doing a full broadcast. @@ -221,25 +168,17 @@ async fn list_from_cache(use_table: bool) { let host_state = lease_bridge_config().await; let bridges = host_state.list_bridges(); if bridges.is_empty() { - if SHOULD_LOG_JSON() { - info!(id = "bridgectl::list::cache_has_no_bridges", ?host_state); - } else { - info!( - host_state.path=%host_state.get_path().display(), - "Couldn't find any cached bridges (perhaps try without the cached flag, or validate the path?). You can use `bridgectl add` to add bridges to your host state.", - ); - } + info!( + id = "bridgectl::list::cache_has_no_bridges", + host_state.path=%host_state.get_path().display(), + "Couldn't find any cached bridges (perhaps try without the cached flag, or validate the path?). You can use `bridgectl add` to add bridges to your host state.", + ); return; } if use_table { - if SHOULD_LOG_JSON() { - info!(id = TABLE_TRACING_ID, line = TABLE_HEADER); - info!(id = TABLE_TRACING_ID, line = TABLE_HEADER_LINE); - } else { - println!("{TABLE_HEADER}"); - println!("{TABLE_HEADER_LINE}"); - } + info!(id = TABLE_TRACING_ID, TABLE_HEADER); + info!(id = TABLE_TRACING_ID, TABLE_HEADER_LINE); } for (bridge_name, (bridge_ip, is_default)) in bridges { @@ -253,21 +192,17 @@ async fn list_from_cache(use_table: bool) { format!("{name} | {ip} | {is_default}") }; - if SHOULD_LOG_JSON() { - info!( - id = TABLE_TRACING_ID, - line = table_line, - bridge.ip = ?bridge_ip, - bridge.is_default = is_default, - bridge.name = bridge_name, - ); - } else { - println!("{table_line}"); - } - } else if SHOULD_LOG_JSON() { - info!(id = "bridgectl::list::bridge_info", bridge.ip = ?bridge_ip, bridge.is_default = is_default, bridge.name = bridge_name); + + info!( + id = TABLE_TRACING_ID, + bridge.ip = ?bridge_ip, + bridge.is_default = is_default, + bridge.name = bridge_name, + table_line, + ); } else { info!( + id = "bridgectl::list::bridge_info", bridge.ip_address = bridge_ip.map_or("".to_owned(), |ip| format!("{ip}")), bridge.is_default = is_default, diff --git a/cmd/bridgectl/src/commands/list_serial_ports.rs b/cmd/bridgectl/src/commands/list_serial_ports.rs index 2e9e38d..a33647f 100644 --- a/cmd/bridgectl/src/commands/list_serial_ports.rs +++ b/cmd/bridgectl/src/commands/list_serial_ports.rs @@ -1,69 +1,37 @@ //! Handling listing all the available serial ports known on your network. -use crate::{ - SHOULD_LOG_JSON, - exit_codes::{LSSP_FAILED_ENUMERATION, LSSP_NO_PORTS}, -}; +use crate::exit_codes::{LSSP_FAILED_ENUMERATION, LSSP_NO_PORTS}; use cat_dev::serial::SyncSerialPort; -use miette::miette; use tracing::{error, info}; pub fn handle_list_serial_ports() { let ports = match SyncSerialPort::available_ports() { Ok(ports) => ports, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::list_serial_ports::could_not_enumerate_ports", - ?cause, - "failed to enumerate serial-ports", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "Please report this issue for extra debugging support.", - "OS error attempting to list serial ports", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::list_serial_ports::could_not_enumerate_ports", + ?cause, + "failed to enumerate serial-ports", + ); std::process::exit(LSSP_FAILED_ENUMERATION); } }; if ports.is_empty() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::list_serial_ports::no_ports_found", - "os returned 0 serial ports being found" - ); - } else { - error!( - "\n{:?}", - miette!( - help = "If you have a serial port device plugged in and recognized, please report an issue.", - "Your OS returned 0 serial ports that were usable", - ) - ); - } + error!( + id = "bridgectl::list_serial_ports::no_ports_found", + "os returned 0 serial ports being found" + ); std::process::exit(LSSP_NO_PORTS); } for port in ports { - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::list_serial_ports::found_port", - port = %port.display(), - "found a serial port", - ); - } else { - info!( - port = %port.display(), - "Found a usable serial port!", - ); - } + info!( + id = "bridgectl::list_serial_ports::found_port", + port = %port.display(), + "found a serial port", + ); } } diff --git a/cmd/bridgectl/src/commands/mion/decrypt_firmware.rs b/cmd/bridgectl/src/commands/mion/decrypt_firmware.rs index 3f66750..2eb4e65 100644 --- a/cmd/bridgectl/src/commands/mion/decrypt_firmware.rs +++ b/cmd/bridgectl/src/commands/mion/decrypt_firmware.rs @@ -1,15 +1,11 @@ //! Handle decrypting a MION firmware file distributed as part of the Cafe SDK. -use crate::{ - SHOULD_LOG_JSON, - exit_codes::{ - DECRYPT_FW_BAD_OUTPUT_PATH, DECRYPT_FW_COULD_NOT_DECRYPT_FW, DECRYPT_FW_COULD_NOT_READ_FW, - DECRYPT_FW_COULD_NOT_WRITE_FW, - }, - utils::add_context_to, +use crate::exit_codes::{ + DECRYPT_FW_BAD_OUTPUT_PATH, DECRYPT_FW_COULD_NOT_DECRYPT_FW, DECRYPT_FW_COULD_NOT_READ_FW, + DECRYPT_FW_COULD_NOT_WRITE_FW, }; use cat_dev::mion::firmware::raw_decrypt; -use miette::{IntoDiagnostic, miette}; +use miette::IntoDiagnostic; use std::path::{Path, PathBuf}; use tracing::{error, field::valuable}; @@ -25,28 +21,12 @@ pub async fn handle_decrypt_firmware( { Ok(bytes) => bytes, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::decrypt_firmware::could_not_read_firmware_file", - ?cause, - file = valuable(&firmware_file), - "Could not read firmware file to decrypt.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not read the firmware file to decrypt, perhaps some filesystem error?" - ), - [ - cause, - miette!(format!("Was Reading File: {}", firmware_file.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::decrypt_firmware::could_not_read_firmware_file", + ?cause, + file = valuable(&firmware_file), + "Could not read firmware file to decrypt.", + ); std::process::exit(DECRYPT_FW_COULD_NOT_READ_FW); } @@ -57,28 +37,12 @@ pub async fn handle_decrypt_firmware( match raw_decrypt(&encrypted_firmware_contents[..encrypted_firmware_contents.len() - 6]) { Ok(contents) => contents, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::decrypt_firmware::could_not_decrypt", - ?cause, - file = valuable(&firmware_file), - "Could not decrypt the firmware file, must be corrupt.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not decrypt the firmware file, perhaps it is corrupt in some way?" - ), - [ - cause.into(), - miette!(format!("Was Reading File: {}", firmware_file.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::decrypt_firmware::could_not_decrypt", + ?cause, + file = valuable(&firmware_file), + "Could not decrypt the firmware file, must be corrupt.", + ); std::process::exit(DECRYPT_FW_COULD_NOT_DECRYPT_FW); } @@ -93,28 +57,12 @@ pub async fn handle_decrypt_firmware( .await .into_diagnostic() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::decrypt_firmware::could_not_write_decrypted_firmware_file", - ?cause, - output_file = valuable(&output_path), - "Could not write decrypted file contents.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not write the decrypted firmware file, perhaps some filesystem error?" - ), - [ - cause, - miette!(format!("Was Writing File: {}", output_path.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::decrypt_firmware::could_not_write_decrypted_firmware_file", + ?cause, + output_file = valuable(&output_path), + "Could not write decrypted file contents.", + ); std::process::exit(DECRYPT_FW_COULD_NOT_WRITE_FW); } @@ -128,20 +76,12 @@ fn get_output_path( if (output_path_flag.is_some() && output_path_positional.is_some()) && output_path_flag != output_path_positional { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::decrypt_firmware::conflicting_output_paths", - flag.output = valuable(&output_path_flag), - argument.output = valuable(&output_path_positional), - "Specified the Output Path twice with different values, not sure where to output.", - ); - } else { - error!( - flag.output = valuable(&output_path_flag), - argument.output = valuable(&output_path_positional), - "Specified the Output Path twice with different values, not sure where to output.", - ); - } + error!( + id = "bridgectl::mion::decrypt_firmware::conflicting_output_paths", + flag.output = valuable(&output_path_flag), + argument.output = valuable(&output_path_positional), + "Specified the Output Path twice with different values, not sure where to output.", + ); std::process::exit(DECRYPT_FW_BAD_OUTPUT_PATH); } diff --git a/cmd/bridgectl/src/commands/mion/dump_eeprom.rs b/cmd/bridgectl/src/commands/mion/dump_eeprom.rs index c16e454..3c7c71d 100644 --- a/cmd/bridgectl/src/commands/mion/dump_eeprom.rs +++ b/cmd/bridgectl/src/commands/mion/dump_eeprom.rs @@ -1,12 +1,10 @@ //! Dump the EEPROM for a running CAT-DEV. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::get_targeted_bridge_ip, exit_codes::{DUMP_EEPROM_FAILURE, FAILED_TO_WRITE_TO_DISK}, }; use cat_dev::mion::cgis::dump_eeprom; -use miette::miette; use std::path::PathBuf; use tokio::fs::write; use tracing::{error, info}; @@ -14,18 +12,11 @@ use tracing::{error, info}; /// Actual command handler for the `mion dump-eeprom` command. pub async fn handle_dump_eeprom(output_path: Option) { let bridge_ip = get_targeted_bridge_ip().await; - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::mion::dump_eeprom::start", - %bridge_ip, - "Dumping MION EEPROM...", - ); - } else { - info!( - %bridge_ip, - "Dumping MION EEPROM...", - ); - } + info!( + id = "bridgectl::mion::dump_eeprom::start", + %bridge_ip, + "Dumping MION EEPROM...", + ); match dump_eeprom(bridge_ip).await { Ok(memory) => { @@ -36,39 +27,25 @@ pub async fn handle_dump_eeprom(output_path: Option) { }; if let Some(cause) = err { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_eeprom::write_failure", - %bridge_ip, - ?cause, - path = output_path.map_or("eeprom-memory.bin".to_owned(), |p| p.to_string_lossy().to_string()), - "Failed to write eeprom memory to disk!", - ); - } else { - error!( - "\n{:?}", - miette!("Could not write successfully dumped MION's EEPROM Memory") - .wrap_err(cause), - ); - } - - std::process::exit(FAILED_TO_WRITE_TO_DISK); - } - } - Err(cause) => { - if SHOULD_LOG_JSON() { error!( - id = "bridgectl::mion::dump_eeprom::failure", + id = "bridgectl::mion::dump_eeprom::write_failure", %bridge_ip, ?cause, - "Failure to dump MION's EEPROM memory", - ); - } else { - error!( - "\n{:?}", - miette!("Could not dump MION's EEPROM Memory.").wrap_err(cause), + path = output_path.map_or("eeprom-memory.bin".to_owned(), |p| p.to_string_lossy().to_string()), + "Failed to write eeprom memory to disk!", ); + + std::process::exit(FAILED_TO_WRITE_TO_DISK); } + } + Err(cause) => { + error!( + id = "bridgectl::mion::dump_eeprom::open_failure", + %bridge_ip, + ?cause, + path = output_path.map_or("eeprom-memory.bin".to_owned(), |p| p.to_string_lossy().to_string()), + "Failed to open file where we planned on writing MION's EEPMROM too!", + ); std::process::exit(DUMP_EEPROM_FAILURE); } diff --git a/cmd/bridgectl/src/commands/mion/dump_firmware_from_memory.rs b/cmd/bridgectl/src/commands/mion/dump_firmware_from_memory.rs index ab9d703..90f3d47 100644 --- a/cmd/bridgectl/src/commands/mion/dump_firmware_from_memory.rs +++ b/cmd/bridgectl/src/commands/mion/dump_firmware_from_memory.rs @@ -5,12 +5,10 @@ //! 3 to be safe). use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::get_targeted_bridge_ip, exit_codes::{DUMP_MEMORY_FAILURE, FAILED_TO_WRITE_TO_DISK}, }; use cat_dev::mion::cgis::dump_memory_with_writer; -use miette::miette; use std::{ fs::OpenOptions, io::{BufWriter, Write}, @@ -27,18 +25,11 @@ const EARLY_FW_STOP: usize = 3_146_240_usize; /// Actual command handler for the `mion dump-firmware-from-memory` command. pub async fn handle_dump_firmware_from_memory(output_path: Option) { let bridge_ip = get_targeted_bridge_ip().await; - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::mion::dump_firmware_from_memory::start", - %bridge_ip, - "Dumping MION FW from Memory, this may take a bit (a couple hours max)...", - ); - } else { - info!( - %bridge_ip, - "Dumping MION FW from Memory, this may take a bit (a couple hours max)...", - ); - } + info!( + id = "bridgectl::mion::dump_firmware_from_memory::start", + %bridge_ip, + "Dumping MION FW from Memory, this may take a bit (a couple hours max)...", + ); let path = output_path.unwrap_or(PathBuf::from("88F6281-firmware-memory.bin")); let file_writer = match OpenOptions::new() @@ -50,21 +41,13 @@ pub async fn handle_dump_firmware_from_memory(output_path: Option) { { Ok(val) => val, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_firmware_from_memory::write_failure", - %bridge_ip, - ?cause, - path = %path.to_string_lossy(), - "Failed to write 88F6281 memory to disk!", - ); - } else { - error!( - "\n{:?}", - miette!("Could not write successfully dumped MION's 88F6281 Memory") - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_firmware_from_memory::open_failure", + %bridge_ip, + ?cause, + path = %path.to_string_lossy(), + "Failed to open file where MION's 88F6281 FW was going to be written!", + ); std::process::exit(FAILED_TO_WRITE_TO_DISK); } @@ -74,40 +57,25 @@ pub async fn handle_dump_firmware_from_memory(output_path: Option) { if let Err(cause) = dump_memory_with_writer(bridge_ip, None, Some(EARLY_FW_STOP), |bytes: Vec| { if let Err(cause) = buff_writer.write(&bytes) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_firmware_from_memory::write_failure", - %bridge_ip, - ?cause, - path = %path.to_string_lossy(), - "Failed to write 88F6281 memory to disk!", - ); - } else { - error!( - "\n{:?}", - miette!("Could not write successfully dumped MION's 88F6281 Memory") - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_firmware_from_memory::write_failure", + %bridge_ip, + ?cause, + path = %path.to_string_lossy(), + "Failed to write MION's 88F6281 FW to disk!", + ); std::process::exit(FAILED_TO_WRITE_TO_DISK); } }) .await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_firmware_from_memory::failure", - %bridge_ip, - ?cause, - "Failure to dump MION's memory", - ); - } else { - error!( - "\n{:?}", - miette!("Could not dump MION's Memory.").wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_firmware_from_memory::failure", + %bridge_ip, + ?cause, + "Failure to dump MION's memory", + ); std::process::exit(DUMP_MEMORY_FAILURE); } diff --git a/cmd/bridgectl/src/commands/mion/dump_memory.rs b/cmd/bridgectl/src/commands/mion/dump_memory.rs index b9774b2..9007a1c 100644 --- a/cmd/bridgectl/src/commands/mion/dump_memory.rs +++ b/cmd/bridgectl/src/commands/mion/dump_memory.rs @@ -1,12 +1,10 @@ //! Dump the memory for a running CAT-DEV. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::get_targeted_bridge_ip, exit_codes::{DUMP_MEMORY_FAILURE, FAILED_TO_WRITE_TO_DISK}, }; use cat_dev::mion::cgis::dump_memory_with_writer; -use miette::miette; use std::{ fs::OpenOptions, io::{BufWriter, Write}, @@ -17,18 +15,11 @@ use tracing::{error, info}; /// Actual command handler for the `mion dump-memory` command. pub async fn handle_dump_memory(output_path: Option, resume_at: Option) { let bridge_ip = get_targeted_bridge_ip().await; - if SHOULD_LOG_JSON() { - info!( - id = "bridgectl::mion::dump_memory::start", - %bridge_ip, - "Dumping MION Memory, this will take a LONG time (like days...)...", - ); - } else { - info!( - %bridge_ip, - "Dumping MION Memory, this will take a LONG time (like days...)...", - ); - } + info!( + id = "bridgectl::mion::dump_memory::start", + %bridge_ip, + "Dumping MION Memory, this will take a LONG time (like days...)...", + ); let path = output_path.unwrap_or(PathBuf::from("88F6281-memory.bin")); let file_writer = match OpenOptions::new() @@ -39,21 +30,13 @@ pub async fn handle_dump_memory(output_path: Option, resume_at: Option< { Ok(val) => val, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_memory::write_failure", - %bridge_ip, - ?cause, - path = %path.to_string_lossy(), - "Failed to write 88F6281 memory to disk!", - ); - } else { - error!( - "\n{:?}", - miette!("Could not write successfully dumped MION's 88F6281 Memory") - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_memory::open_failure", + %bridge_ip, + ?cause, + path = %path.to_string_lossy(), + "Failed to open output file for MION's 88F6281 memory!", + ); std::process::exit(FAILED_TO_WRITE_TO_DISK); } @@ -62,40 +45,25 @@ pub async fn handle_dump_memory(output_path: Option, resume_at: Option< if let Err(cause) = dump_memory_with_writer(bridge_ip, resume_at, None, |bytes: Vec| { if let Err(cause) = buff_writer.write(&bytes) { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_memory::write_failure", - %bridge_ip, - ?cause, - path = %path.to_string_lossy(), - "Failed to write 88F6281 memory to disk!", - ); - } else { - error!( - "\n{:?}", - miette!("Could not write successfully dumped MION's 88F6281 Memory") - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_memory::write_failure", + %bridge_ip, + ?cause, + path = %path.to_string_lossy(), + "Failed to write MION's 88F6281 memory to disk!", + ); std::process::exit(FAILED_TO_WRITE_TO_DISK); } }) .await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::dump_memory::failure", - %bridge_ip, - ?cause, - "Failure to dump MION's memory", - ); - } else { - error!( - "\n{:?}", - miette!("Could not dump MION's Memory.").wrap_err(cause), - ); - } + error!( + id = "bridgectl::mion::dump_memory::failure", + %bridge_ip, + ?cause, + "Failure to dump MION's memory", + ); std::process::exit(DUMP_MEMORY_FAILURE); } diff --git a/cmd/bridgectl/src/commands/mion/encrypt_firmware.rs b/cmd/bridgectl/src/commands/mion/encrypt_firmware.rs index e55eef0..9dc0774 100644 --- a/cmd/bridgectl/src/commands/mion/encrypt_firmware.rs +++ b/cmd/bridgectl/src/commands/mion/encrypt_firmware.rs @@ -1,15 +1,11 @@ //! Handle encrypting a MION firmware file distributed as part of the Cafe SDK. -use crate::{ - SHOULD_LOG_JSON, - exit_codes::{ - ENCRYPT_FW_BAD_OUTPUT_PATH, ENCRYPT_FW_COULD_NOT_ENCRYPT_FW, ENCRYPT_FW_COULD_NOT_READ_FW, - ENCRYPT_FW_COULD_NOT_WRITE_FW, - }, - utils::add_context_to, +use crate::exit_codes::{ + ENCRYPT_FW_BAD_OUTPUT_PATH, ENCRYPT_FW_COULD_NOT_ENCRYPT_FW, ENCRYPT_FW_COULD_NOT_READ_FW, + ENCRYPT_FW_COULD_NOT_WRITE_FW, }; use cat_dev::mion::firmware::raw_encrypt; -use miette::{IntoDiagnostic, miette}; +use miette::IntoDiagnostic; use std::path::{Path, PathBuf}; use tracing::{error, field::valuable}; @@ -25,28 +21,12 @@ pub async fn handle_encrypt_firmware( { Ok(bytes) => bytes, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::encrypt_firmware::could_not_read_firmware_file", - ?cause, - file = valuable(&firmware_file), - "Could not read firmware file to encrypt.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not read the firmware file to encrypt, perhaps some filesystem error?" - ), - [ - cause, - miette!(format!("Was Reading File: {}", firmware_file.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::encrypt_firmware::could_not_read_firmware_file", + ?cause, + file = valuable(&firmware_file), + "Could not read firmware file to encrypt.", + ); std::process::exit(ENCRYPT_FW_COULD_NOT_READ_FW); } @@ -57,28 +37,12 @@ pub async fn handle_encrypt_firmware( match raw_encrypt(&decrypted_firmware_contents[..decrypted_firmware_contents.len() - 6]) { Ok(contents) => contents, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::encrypt_firmware::could_not_encrypt", - ?cause, - file = valuable(&firmware_file), - "Could not encrypt the firmware file, must be corrupt.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not encrypt the firmware file, perhaps it is corrupt in some way?" - ), - [ - cause.into(), - miette!(format!("Was Reading File: {}", firmware_file.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::encrypt_firmware::could_not_encrypt", + ?cause, + file = valuable(&firmware_file), + "Could not encrypt the firmware file, must be corrupt.", + ); std::process::exit(ENCRYPT_FW_COULD_NOT_ENCRYPT_FW); } @@ -93,28 +57,12 @@ pub async fn handle_encrypt_firmware( .await .into_diagnostic() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::encrypt_firmware::could_not_write_encrypted_firmware_file", - ?cause, - output_file = valuable(&output_path), - "Could not write encrypted file contents.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Could not write the encrypted firmware file, perhaps some filesystem error?" - ), - [ - cause, - miette!(format!("Was Writing File: {}", output_path.display())), - ] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::mion::encrypt_firmware::could_not_write_encrypted_firmware_file", + ?cause, + output_file = valuable(&output_path), + "Could not write encrypted file contents.", + ); std::process::exit(ENCRYPT_FW_COULD_NOT_WRITE_FW); } @@ -128,20 +76,12 @@ fn get_output_path( if (output_path_flag.is_some() && output_path_positional.is_some()) && output_path_flag != output_path_positional { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::mion::encrypt_firmware::conflicting_output_paths", - flag.output = valuable(&output_path_flag), - argument.output = valuable(&output_path_positional), - "Specified the Output Path twice with different values, not sure where to output.", - ); - } else { - error!( - flag.output = valuable(&output_path_flag), - argument.output = valuable(&output_path_positional), - "Specified the Output Path twice with different values, not sure where to output.", - ); - } + error!( + id = "bridgectl::mion::encrypt_firmware::conflicting_output_paths", + flag.output = valuable(&output_path_flag), + argument.output = valuable(&output_path_positional), + "Specified the Output Path twice with different values, not sure where to output.", + ); std::process::exit(ENCRYPT_FW_BAD_OUTPUT_PATH); } diff --git a/cmd/bridgectl/src/commands/remove.rs b/cmd/bridgectl/src/commands/remove.rs index cd41e09..83186d3 100644 --- a/cmd/bridgectl/src/commands/remove.rs +++ b/cmd/bridgectl/src/commands/remove.rs @@ -3,12 +3,9 @@ //! Specifically remove a bridge from your host state file aka your `bridge_env.ini`. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{get_targeted_bridge_name, lease_bridge_config_mut}, exit_codes::{REMOVE_BRIDGE_DOESNT_EXIST, REMOVE_COULD_NOT_SAVE_TO_DISK}, - utils::add_context_to, }; -use miette::miette; use tracing::{error, info}; /// Handle the removal of a bridge. @@ -25,53 +22,25 @@ pub async fn handle_remove_bridge() { ); } } else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::rm::bridge_doesnt_exist", - bridge.name = %name, - host_state.path = %host_state.get_path().display(), - "cannot remove a bridge that does not exist", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("cannot remove a bridge that does not exist"), - [miette!( - "Please ensure the bridge name {name} isn't mispelled and is present in the state file at: {}", - host_state.get_path().display(), - )] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::rm::bridge_doesnt_exist", + bridge.name = %name, + host_state.path = %host_state.get_path().display(), + "cannot remove a bridge that does not exist", + ); std::process::exit(REMOVE_BRIDGE_DOESNT_EXIST); } host_state.remove_bridge(&name); if let Err(cause) = host_state.write_to_disk().await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::rm::could_not_save_to_disk", - bridge.name = %name, - host_state.path = %host_state.get_path().display(), - ?cause, - "could not save changed to disk", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "While trying to remove bridge named {name} from: {}", - host_state.get_path().display() - ), - "could not save changes directly to disk", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::rm::could_not_save_to_disk", + bridge.name = %name, + host_state.path = %host_state.get_path().display(), + ?cause, + "could not save changed to disk", + ); std::process::exit(REMOVE_COULD_NOT_SAVE_TO_DISK); } diff --git a/cmd/bridgectl/src/commands/set_default.rs b/cmd/bridgectl/src/commands/set_default.rs index 805654a..df76af4 100644 --- a/cmd/bridgectl/src/commands/set_default.rs +++ b/cmd/bridgectl/src/commands/set_default.rs @@ -4,12 +4,9 @@ //! system. use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{get_targeted_bridge_name, lease_bridge_config_mut}, exit_codes::{SET_DEFAULT_BRIDGE_DOESNT_EXIST, SET_DEFAULT_COULD_NOT_SAVE_TO_DISK}, - utils::add_context_to, }; -use miette::miette; use tracing::{error, info}; /// Handle the set default bridge command. @@ -18,26 +15,12 @@ pub async fn handle_set_default_bridge() { let mut host_state = lease_bridge_config_mut().await; if host_state.get_bridge(&name).is_none() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_default::bridge_doesnt_exist", - bridge.name = %name, - host_state.path = %host_state.get_path().display(), - "cannot set a bridge as the default that does not exist", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("cannot set a bridge as the default that does not exist"), - [miette!( - "Please ensure the bridge name {name} isn't mispelled and is present in the state file at: {}", - host_state.get_path().display(), - )] - .into_iter(), - ), - ); - } + error!( + id = "bridgectl::set_default::bridge_doesnt_exist", + bridge.name = %name, + host_state.path = %host_state.get_path().display(), + "cannot set a bridge as the default that does not exist", + ); std::process::exit(SET_DEFAULT_BRIDGE_DOESNT_EXIST); } @@ -47,27 +30,13 @@ pub async fn handle_set_default_bridge() { _ = host_state.set_default_bridge(&name); if let Err(cause) = host_state.write_to_disk().await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_default::could_not_save_to_disk", - bridge.name = %name, - host_state.path = %host_state.get_path().display(), - ?cause, - "could not save changed to disk", - ); - } else { - error!( - "\n{:?}", - miette!( - help = format!( - "While trying to set bridge named {name} as the default bridge for: {}", - host_state.get_path().display() - ), - "could not save changes directly to disk", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::set_default::could_not_save_to_disk", + bridge.name = %name, + host_state.path = %host_state.get_path().display(), + ?cause, + "could not save changed to disk", + ); std::process::exit(SET_DEFAULT_COULD_NOT_SAVE_TO_DISK); } diff --git a/cmd/bridgectl/src/commands/set_parameters.rs b/cmd/bridgectl/src/commands/set_parameters.rs index c0ad9c8..6281db3 100644 --- a/cmd/bridgectl/src/commands/set_parameters.rs +++ b/cmd/bridgectl/src/commands/set_parameters.rs @@ -1,17 +1,14 @@ use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::{get_byte_value, get_targeted_bridge_ip}, exit_codes::{ SET_PARAMS_FAILED_TO_SET_PARAMS, SET_PARAMS_INVALID_PARAMETER_SET_STRING, SET_PARAMS_INVALID_PARAMETER_VALUE, SET_PARAMS_NO_PARAMETERS_SPECIFIED, }, - utils::add_context_to, }; use cat_dev::mion::{ parameter::set_parameters, proto::parameter::well_known::{ParameterLocationSpecification, validate_value_at_index}, }; -use miette::miette; use std::net::Ipv4Addr; use tracing::{error, field::valuable, info, warn}; @@ -26,37 +23,23 @@ pub async fn handle_set_parameters( let param_filters = parse_parameters_to_set_list(¶ms); let bridge_ip = get_targeted_bridge_ip().await; do_set_parameters(bridge_ip, parameter_space_port, param_filters).await; - } else if let Some(params) = bridge_or_params_arguments { - if !used_first_arg { - let param_filters = parse_parameters_to_set_list(¶ms); - let bridge_ip = get_targeted_bridge_ip().await; - do_set_parameters(bridge_ip, parameter_space_port, param_filters).await; - } + } else if let Some(params) = bridge_or_params_arguments + && !used_first_arg + { + let param_filters = parse_parameters_to_set_list(¶ms); + let bridge_ip = get_targeted_bridge_ip().await; + do_set_parameters(bridge_ip, parameter_space_port, param_filters).await; } - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_parameters::no_params", - suggestions = valuable(&[ - "You can run `bridgectl set-params `, `bridgectl sp --default `, etc.", - "If running in a mochiato/cafe/cafex environment you can run: `bridgectl set-params `.", - "You can run `bridgectl set-params --help` to get more information.", - ]), - "No parameter arguments passed to `bridgectl set-params`, but we need a list of parameters to fetch!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("No parameter arguments passed to `bridgectl set-params`, but we need a list of parameters to fetch"), - [ - miette!("You can run `bridgectl set-params `, `bridgectl sp --default `, etc."), - miette!("If running in a mochiato/cafe/cafex environment you can run: `bridgectl set-params `."), - miette!("You can run `bridgectl set-params --help` to get more information on how to use this command."), - ].into_iter(), - ), - ); - } + error!( + id = "bridgectl::set_parameters::no_params", + suggestions = valuable(&[ + "You can run `bridgectl set-params `, `bridgectl sp --default `, etc.", + "If running in a mochiato/cafe/cafex environment you can run: `bridgectl set-params `.", + "You can run `bridgectl set-params --help` to get more information.", + ]), + "No parameter arguments passed to `bridgectl set-params`, but we need a list of parameters to fetch!", + ); std::process::exit(SET_PARAMS_NO_PARAMETERS_SPECIFIED); } @@ -74,25 +57,17 @@ async fn do_set_parameters( .await { Ok(_) => { - info!("Successfully set your parameters!"); + info!( + id = "bridgectl::set_parameters::success", + "Successfully set your parameters!", + ); } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_parameters::failed_to_execute_set_parameters", - ?cause, - help = "We could not send/receive a packet to your MION to set it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", - ); - } else { - error!( - "\n{:?}", - miette!( - help = "If you leave a MION running for too long it may stop responding to parameter requests.", - "Could not send/receive a packet to your MION to set it's parameters, please ensure the device is running.", - ) - .wrap_err(cause), - ); - } + error!( + id = "bridgectl::set_parameters::failed_to_execute_set_parameters", + ?cause, + help = "We could not send/receive a packet to your MION to set it's parameters, please ensure it is running. If it's been running for awhile, it may need a reboot.", + ); std::process::exit(SET_PARAMS_FAILED_TO_SET_PARAMS); } @@ -105,18 +80,11 @@ fn parse_parameters_to_set_list( let mut locations = Vec::new(); for potential_serialized_specification in parameters_string.split(',') { let Some(found_equals_location) = potential_serialized_specification.find('=') else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_parameters::no_equals_sign", - parameter = %potential_serialized_specification, - line = "Parameters in set parameters should be in the format `(name or idx)=(value)`, but noe quals sign was found!", - ); - } else { - error!( - parameter = %potential_serialized_specification, - "Parameters for set-parameters should be in the format `(name or idx)=(value)` e.g. `major=2`, or `3=5`!", - ); - } + error!( + id = "bridgectl::set_parameters::no_equals_sign", + parameter = %potential_serialized_specification, + "Parameters in set parameters should be in the format `(name or idx)=(value)`, but noe quals sign was found!", + ); std::process::exit(SET_PARAMS_INVALID_PARAMETER_SET_STRING); }; @@ -127,55 +95,32 @@ fn parse_parameters_to_set_list( str_value = &str_value[1..]; let Ok(specification) = ParameterLocationSpecification::try_from(index_or_name) else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_parameters::bad_parameter_name", - parameter.name = %index_or_name, - line = "Parameter name wasn't known, or index wasn't within range of (0-511 inclusive).", - ); - } else { - error!( - parameter.name = %index_or_name, - "Parameter name was not known, or it was an index who wasn't within the range of 0-511." - ); - } + error!( + id = "bridgectl::set_parameters::bad_parameter_name", + parameter.name = %index_or_name, + "Parameter name wasn't known, or index wasn't within range of (0-511 inclusive).", + ); std::process::exit(SET_PARAMS_INVALID_PARAMETER_SET_STRING); }; let Ok(value_as_byte) = get_byte_value(str_value) else { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::set_parameters::bad_parameter_value", - parameter.name = %index_or_name, - parameter.value = %str_value, - line = "Parameters can only be set to a byte value (0-255 inclusive).", - ); - } else { - error!( - parameter.name = %index_or_name, - parameter.value = %str_value, - line = "Parameters can only be set to a byte value (0-255 inclusive), your value could not be parsed as a number in that range.", - ); - } + error!( + id = "bridgectl::set_parameters::bad_parameter_value", + parameter.name = %index_or_name, + parameter.value = %str_value, + "Parameters can only be set to a byte value (0-255 inclusive).", + ); std::process::exit(SET_PARAMS_INVALID_PARAMETER_VALUE); }; if !validate_value_at_index(&specification, value_as_byte) { - if SHOULD_LOG_JSON() { - warn!( - id = "bridgectl::set_parameters::invalid_parameter_value", - parameter.name = ?specification, - parameter.value = value_as_byte, - "this value is not valid for the location", - ); - } else { - warn!( - parameter.name = ?specification, - parameter.value = value_as_byte, - "This parameter value is not valid, and may run into various errors.", - ); - } + warn!( + id = "bridgectl::set_parameters::invalid_parameter_value", + parameter.name = ?specification, + parameter.value = value_as_byte, + "this value is not valid for the location", + ); } locations.push((specification, value_as_byte)); diff --git a/cmd/bridgectl/src/commands/tail.rs b/cmd/bridgectl/src/commands/tail.rs index 5e657bd..e9ba21b 100644 --- a/cmd/bridgectl/src/commands/tail.rs +++ b/cmd/bridgectl/src/commands/tail.rs @@ -1,11 +1,8 @@ use crate::{ - SHOULD_LOG_JSON, commands::argv_helpers::coalesce_serial_ports, exit_codes::{TAIL_COULD_NOT_SPAWN, TAIL_NO_SERIAL_PORT}, knobs::cli::SharedSerialPortFlags, - utils::add_context_to, }; -use miette::miette; use std::path::PathBuf; use tracing::error; @@ -18,40 +15,20 @@ pub async fn handle_tail( coalesce_serial_ports(&serial_port_flags, serial_port_positional.as_ref()).await; if !serial_reader.has_serial_port() { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::tail::no_serial_port", - "tail requires a serial port to connect too for now" - ); - } else { - error!( - "\n{:?}", - miette!("Tailing currently requires an active connection to the serial port."), - ); - } + error!( + id = "bridgectl::tail::no_serial_port", + "tail requires a serial port to connect too for now" + ); std::process::exit(TAIL_NO_SERIAL_PORT); } if let Err(cause) = serial_reader.spawn_log_task().await { - if SHOULD_LOG_JSON() { - error!( - id = "bridgectl::tail::failed_to_join_task", - ?cause, - "internal error: could not spawn/join task." - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("{cause:?}"), - [miette!( - "internal error: could not spawn/join tasks on a thread pool" - )] - .into_iter() - ), - ); - } + error!( + id = "bridgectl::tail::failed_to_join_task", + ?cause, + "internal error: could not spawn/join task." + ); std::process::exit(TAIL_COULD_NOT_SPAWN); } diff --git a/cmd/bridgectl/src/exit_codes.rs b/cmd/bridgectl/src/exit_codes.rs index c8b0963..c1412e2 100644 --- a/cmd/bridgectl/src/exit_codes.rs +++ b/cmd/bridgectl/src/exit_codes.rs @@ -5,6 +5,7 @@ pub const LOGGING_HANDLER_INSTALL_FAILURE: i32 = 2; pub const SHOULD_NEVER_HAPPEN_FAILURE: i32 = 3; pub const FAILED_TO_WRITE_TO_DISK: i32 = 4; pub const BRIDGE_TOO_OLD_FOR_FEATURE: i32 = 5; +pub const HOST_FILESYSTEM_INIT_FAILURE: i32 = 6; pub const ARGV_PARSE_FAILURE: i32 = 10; pub const ARGV_NO_COMMAND_SPECIFIED: i32 = 11; diff --git a/cmd/bridgectl/src/main.rs b/cmd/bridgectl/src/main.rs index b24c2a7..9fab44e 100644 --- a/cmd/bridgectl/src/main.rs +++ b/cmd/bridgectl/src/main.rs @@ -14,7 +14,6 @@ pub mod commands; pub mod exit_codes; pub mod knobs; -pub mod utils; use crate::{ commands::{ @@ -41,46 +40,31 @@ use crate::{ cli::{CliArguments, MionSubcommands, Subcommands}, env::USE_JSON_OUTPUT, }, - utils::add_context_to, }; -use clap::{ - Parser, - error::{Error as ClapError, ErrorKind as ClapErrorKind}, +use clap::{Parser, error::ErrorKind as ClapErrorKind}; +use rm_lisa::{ + display::{SuperConsole, SuperConsoleFlushGuard, renderers::JSONConsoleRenderer}, + initialize_logging, initialize_with_console, +}; +use std::{ + io::{Stderr, Stdout}, + path::PathBuf, + sync::Arc, }; -use log::install_logging_handlers; -use miette::{IntoDiagnostic, miette}; -use std::path::PathBuf; use tracing::{error, info}; -/// Whether or not we're logging in JSON. -static mut USE_JSON: bool = false; - -/// Whether or not we should log in JSON. -/// -/// Wrapper around the "unsafe" static mutable. This is guaranteed to be -/// safe as it's initialized as the very first thing to be used in the -/// program, and guaranteed to not change after that. -#[allow(non_snake_case)] -#[inline] -#[must_use] -pub fn SHOULD_LOG_JSON() -> bool { - unsafe { USE_JSON } -} - #[allow( // Most of this is just farming out to subcommands which can't be shorter. clippy::too_many_lines, )] #[tokio::main] async fn main() { - let (argv, use_json) = bootstrap_cli(); - unsafe { - USE_JSON = use_json; - } + let (argv, render_guard) = bootstrap_cli(); if argv.help || argv.commands.is_none() || matches!(argv.commands, Some(Subcommands::Help {})) { let should_error = !argv.help && argv.commands.is_none(); handle_help(argv.commands); + std::mem::drop(render_guard); std::process::exit(if should_error { ARGV_NO_COMMAND_SPECIFIED } else { @@ -89,19 +73,12 @@ async fn main() { } let Some(sub_command) = argv.commands else { - if use_json { - error!( - id = "bridgectl::help::internal", - cause = "Didn't call help even when subcommands was none?" - ); - } else { - error!( - "\n{:?}", - miette!( - "internal error: Failed to specify a single command, and didn't call `help` handler?" - ), - ); - } + error!( + id = "bridgectl::help::internal", + cause = "Didn't call help even when subcommands was none?" + ); + + std::mem::drop(render_guard); std::process::exit(SHOULD_NEVER_HAPPEN_FAILURE); }; @@ -386,7 +363,7 @@ async fn main() { } } -fn bootstrap_cli() -> (CliArguments, bool) { +fn bootstrap_cli() -> (CliArguments, SuperConsoleFlushGuard) { let args_opt = CliArguments::try_parse(); let use_json_cli = args_opt.as_ref().map_or_else( @@ -408,64 +385,63 @@ fn bootstrap_cli() -> (CliArguments, bool) { ); let use_json = *USE_JSON_OUTPUT || use_json_cli; - if let Err(cause) = install_logging_handlers(use_json) { - // We have to use a custom panic script here, because logging isn't setup yet. - if use_json { - println!( - r#"{{"id": "bridgectl::logging::install_failure", "inner_display_error": "{}", "message": "Failed to install the logging handlers!"}}"#, - format!("{cause:?}").replace('"', "\\\"") - ); - } else { - println!("Failed to install the logging handler to setup logging:\n{cause:?}"); + let guard: SuperConsoleFlushGuard; + if use_json { + match initialize_with_console(SuperConsole::new_preselected_renderers( + "bctl", + Arc::new(JSONConsoleRenderer::new()), + Arc::new(JSONConsoleRenderer::new()), + )) { + Ok(console) => { + guard = SuperConsoleFlushGuard::new(console); + } + Err(cause) => { + println!( + r#"{{"id": "bridgectl::logging::install_failure", "inner_display_error": "{}", "message": "Failed to install the logging handlers!"}}"#, + format!("{cause:?}") + .replace('"', "\\\"") + .replace('\n', " ") + ); + + std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); + } + } + } else { + match initialize_logging("bctl") { + Ok(console) => { + guard = SuperConsoleFlushGuard::new(console); + } + Err(cause) => { + // We have to use a custom panic script here, because logging isn't setup yet. + println!("Failed to install the logging handler to setup logging:\n{cause:?}"); + std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); + } } - std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); } match args_opt { - Ok(args) => (args, use_json), + Ok(args) => (args, guard), Err(cause) => { if cause.kind() == ClapErrorKind::DisplayVersion { - if use_json { - info!( - id = "bridgectl::cli::print_version", - version = format!( - "{} ({})", - format!("{}", cause.render()).trim(), - option_env!("BRIDGECTL_BUILD").unwrap_or("unknown") - ), - ); - } else { - info!( - "{}", - format!( - "{} ({})", - format!("{}", cause.render()).trim(), - option_env!("BRIDGECTL_BUILD").unwrap_or("unknown") - ), - ); - } + info!( + id = "bridgectl::cli::print_version", + "{} ({})", + format!("{}", cause.render()).trim(), + option_env!("BRIDGECTL_BUILD").unwrap_or("unknown") + ); + std::mem::drop(guard); std::process::exit(0); } - if use_json { - error!( - id = "bridgectl::cli::arg_parse_failure", - error.kind = %cause.kind(), - error.context = ?cause.context().map(|(kind, value)| format!("{kind}: {value}")).collect::>(), - error.rendered = %cause.render(), - "Failed parsing CLI arguments" - ); - } else { - error!( - "\n{:?}", - add_context_to( - Err::<(), ClapError>(cause).into_diagnostic().unwrap_err(), - [miette!("Failed parsing CLI arguments!")].into_iter(), - ), - ); - } - + error!( + id = "bridgectl::cli::arg_parse_failure", + error.kind = %cause.kind(), + error.context = ?cause.context().map(|(kind, value)| format!("{kind}: {value}")).collect::>(), + error.rendered = %cause.render(), + "Failed parsing CLI arguments" + ); + std::mem::drop(guard); std::process::exit(ARGV_PARSE_FAILURE); } } diff --git a/cmd/bridgectl/src/utils.rs b/cmd/bridgectl/src/utils.rs deleted file mode 100644 index 57da3a1..0000000 --- a/cmd/bridgectl/src/utils.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! Utility functions that don't have one place that they should live. - -use miette::Report; - -/// Add context to a specific error, where you can have like a list of -/// suggestions. -/// -/// NOTE: we cannot reassign a reports severity, so your last items severity -/// is where the real severity gets taken. -pub fn add_context_to( - original_error: Report, - suggestions: impl DoubleEndedIterator, -) -> Report { - let mut latest_error: Option = None; - - for suggestion in suggestions.rev() { - if let Some(last_error) = latest_error { - latest_error = Some(last_error.wrap_err(suggestion)); - } else { - latest_error = Some(suggestion); - } - } - - if let Some(latest) = latest_error { - latest.wrap_err(original_error) - } else { - original_error - } -} diff --git a/cmd/dbg-generate-sata-wal-from-pcap/Cargo.toml b/cmd/dbg-generate-sata-wal-from-pcap/Cargo.toml index 664d091..a71eba4 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/Cargo.toml +++ b/cmd/dbg-generate-sata-wal-from-pcap/Cargo.toml @@ -14,8 +14,8 @@ bytes.workspace = true cat-dev = { default-features = false, features = ["servers"], path = "../../pkg/cat-dev" } clap.workspace = true fnv.workspace = true -log = { path = "../../pkg/log" } miette.workspace = true +rm-lisa.workspace = true rtshark = "^3.2.0" tokio.workspace = true tracing.workspace = true diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/help.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/help.rs index 3fb4c00..8b4d700 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/help.rs +++ b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/help.rs @@ -4,10 +4,7 @@ //! We have to handle `help` ourselves, as opposed to FULLY relying on [`clap`] //! so we can do things like printing the output in JSON. -use crate::{ - SHOULD_LOG_JSON, - knobs::cli::{CliArguments, Subcommands}, -}; +use crate::knobs::cli::{CliArguments, Subcommands}; use clap::{Arg, Command, CommandFactory}; use tracing::{field::valuable, info}; use valuable::Valuable; @@ -22,20 +19,6 @@ pub fn handle_help(opt_sub_command: Option) { let mut top_level_command = CliArguments::command(); let mut subcommands_as_command = Subcommands::command(); - if !SHOULD_LOG_JSON() { - if let Some(sub_command) = opt_sub_command { - let mut subcommands_as_command = Subcommands::command(); - let my_command = subcommands_as_command - .get_subcommands_mut() - .find(|potential_command| sub_command.name_matches(potential_command.get_name())) - .expect("internal error: recognized subcommand could not be matched on name?"); - info!("{}", my_command.render_long_help()); - } else { - info!("{}", top_level_command.render_long_help()); - } - return; - } - let (command, is_top_level) = if let Some(sub_command) = opt_sub_command { let my_command = subcommands_as_command .get_subcommands_mut() @@ -77,11 +60,11 @@ pub fn handle_help(opt_sub_command: Option) { }, help.args = valuable(&args), help.aliases = valuable(&aliases), - help.display_help_text = help, help.options = valuable(&options), help.positionals = valuable(&positionals), help.name = command_name, help.sub_commands = valuable(&subcommands), + help, ); } diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/padlog.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/padlog.rs index 9d33f95..508f4aa 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/padlog.rs +++ b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/padlog.rs @@ -6,12 +6,10 @@ //! on multiple unique ports. use crate::{ - SHOULD_LOG_JSON, commands::utils::{PacketOnPort, PacketsWithDataOnPort, validate_pcap_path_constraints}, exit_codes::{ PADLOG_CANT_CREATE_LOG, PADLOG_FLUSH_FAILURE, PADLOG_NAGLE_FAILURE, PADLOG_WRITE_FAILURE, }, - utils::add_context_to, }; use bytes::{Buf, Bytes, BytesMut}; use cat_dev::{ @@ -25,7 +23,6 @@ use cat_dev::{ net::models::{Endianness, NagleGuard}, }; use fnv::FnvHashMap; -use miette::miette; use std::{ cmp::Ordering as CompareOrdering, collections::{VecDeque, hash_map::Entry}, @@ -382,24 +379,12 @@ fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::open_file_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse open file request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse open file request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::open_file_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse open file request, so cannot determine correct nagle length!", + ); std::process::exit(PADLOG_NAGLE_FAILURE); } @@ -415,24 +400,12 @@ fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::read_file_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse read file request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse read file request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::read_file_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse read file request, so cannot determine correct nagle length!", + ); std::process::exit(PADLOG_NAGLE_FAILURE); } @@ -452,24 +425,12 @@ fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::write_file_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse write file request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse write file request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::write_file_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse write file request, so cannot determine correct nagle length!", + ); std::process::exit(PADLOG_NAGLE_FAILURE); } @@ -484,30 +445,19 @@ fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::ping_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse ping request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse ping request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::ping_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse ping request, so cannot determine correct nagle length!", + ); std::process::exit(PADLOG_NAGLE_FAILURE); } }; info!( + id = "dgswfp::padlog::update_read_write_size", read_size = parsed_data.command_info().user().0, write_size = parsed_data.command_info().user().1, "Updating Connection Read/Write Size", @@ -524,29 +474,13 @@ async fn get_log_writer(log_path: &Path) -> BufWriter { let file = match File::create_new(log_path).await { Ok(fd) => fd, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::padlog::cannot_open_log", - log.path = %log_path.display(), - "Could not create destination log file!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("could not create destination log file"), - [ - miette!("{cause:?}"), - miette!( - "Please ensure the LOG location you specified is correct, and does not exist: {}", - log_path.display(), - ), - ] - .into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::padlog::cannot_open_log", + log.path = %log_path.display(), + help = "Please ensure the LOG location you specified is correct, and does not exist.", + "Could not create destination log file!", + ); std::process::exit(PADLOG_CANT_CREATE_LOG); } @@ -557,21 +491,11 @@ async fn get_log_writer(log_path: &Path) -> BufWriter { async fn do_flush(writer: &mut BufWriter) { if let Err(cause) = writer.flush().await { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::padlog::cannot_flush_log_file", - "Could not write all data to our log file, may be corrupt!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("could not write all data to log file, may be corrupt"), - [miette!("{cause:?}"),].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::padlog::cannot_flush_log_file", + "Could not write all data to our log file, may be corrupt!", + ); std::process::exit(PADLOG_FLUSH_FAILURE); } @@ -579,21 +503,11 @@ async fn do_flush(writer: &mut BufWriter) { fn check_write(result: Result<(), AsyncIOError>) { if let Err(cause) = result { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::padlog::cannot_write_to_buffer", - "Could not write data to our in memory buffer to later flush to a file, OOM?", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("We couldn't write data to our buffered writer, to then flush? OOM?"), - [miette!("{cause:?}"),].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::padlog::cannot_write_to_buffer", + "Could not write data to our in memory buffer to later flush to a file, OOM?", + ); std::process::exit(PADLOG_WRITE_FAILURE); } diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/sata_wal.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/sata_wal.rs index bc80a9d..41a8b65 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/sata_wal.rs +++ b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/sata_wal.rs @@ -1,10 +1,8 @@ //! Handles generation of a SATA WAL log from a PCAPNG. use crate::{ - SHOULD_LOG_JSON, commands::utils::{PacketOnPort, PacketsWithDataOnPort, validate_pcap_path_constraints}, exit_codes::{GENERATE_CANT_CREATE_WAL, GENERATE_NAGLE_FAILURE}, - utils::add_context_to, }; use bytes::{Bytes, BytesMut}; use cat_dev::{ @@ -15,7 +13,6 @@ use cat_dev::{ net::models::{Endianness, NagleGuard}, }; use fnv::FnvHashMap; -use miette::miette; use std::{ collections::hash_map::Entry, path::{Path, PathBuf}, @@ -138,7 +135,10 @@ async fn do_packet_processing( } if nagle_cache.len() < *needed { - debug!("waiting for more data in NeedsAtLeast...."); + debug!( + id = "dgswfp::sata_wal::needs_at_least", + "waiting for more data in NeedsAtLeast....", + ); return; } } @@ -155,16 +155,22 @@ async fn do_packet_processing( } if let SataStreamState::NeedsAtLeastCheckAt(fd, needed_at) = state { // Sniff out read file errors... - if !pkt.is_request() && nagle_cache.starts_with(&[0xC4_u8, 0x00, 0xFE, 0x00, 0x20]) { - let needed = 8 + 24 + 4; - if nagle_cache.len() < needed { - debug!("waiting for more data in error'd NeedsAtLeastCheckAt"); - return; - } + if !pkt.is_request() + && nagle_cache.starts_with(&[0xC4_u8, 0x00, 0xFE, 0x00, 0x20]) + && nagle_cache.len() < 8 + 24 + 4 + { + debug!( + id = "dgswfp::sata_wal::needs_at_least_check_at_error", + "waiting for more data in error'd NeedsAtLeastCheckAt", + ); + return; } if nagle_cache.len() < *needed_at + 4 { - debug!("waiting for more data for length check in NeedsAtLeastCheckAt...."); + debug!( + id = "dgswfp::sata_wal::needs_at_least_check_at", + "waiting for more data for length check in NeedsAtLeastCheckAt....", + ); return; } let read_bytes_or_file_size = u32::from_be_bytes([ @@ -184,9 +190,7 @@ async fn do_packet_processing( if read_bytes_or_file_size < cflags.first_read_size() { // Okay so we're large enough that we got into this state, but we're not // large enough to ignore padding. So switch our state, and pad. - if pkt.is_request() { - unreachable!(); - } else { + if !pkt.is_request() { *state = SataStreamState::NeedsAtLeast( *fd, 0x20 + 0x4 @@ -198,7 +202,10 @@ async fn do_packet_processing( } if nagle_cache.len() < *needed_at + 4 + read_bytes_or_file_size_size { - debug!("waiting for more data in NeedsAtLeastCheckAt...."); + debug!( + id = "dgswfp::sata_wal::needs_more_file_size", + "waiting for more data in NeedsAtLeastCheckAt....", + ); return; } @@ -235,10 +242,6 @@ async fn do_packet_processing( } } -#[allow( - // TODO(mythra): fix - clippy::too_many_lines, -)] async fn process_request( stream_id: u64, packet: Bytes, @@ -261,24 +264,12 @@ async fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::read_file_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse read file request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse read file request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::read_file_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse read file request, so cannot determine correct nagle length!", + ); std::process::exit(GENERATE_NAGLE_FAILURE); } @@ -305,24 +296,12 @@ async fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::write_file_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse write file request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse write file request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::write_file_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse write file request, so cannot determine correct nagle length!", + ); std::process::exit(GENERATE_NAGLE_FAILURE); } @@ -340,30 +319,19 @@ async fn process_request( let parsed_data = match SataRequest::::try_from(packet.clone()) { Ok(d) => d, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::ping_parse_failure", - packet = format!("{packet:02x?}"), - "Failed to parse ping request, so cannot determine correct nagle length!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!( - "Failed to parse ping request, so cannot determine correct nagle length!" - ), - [cause.into()].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::ping_parse_failure", + packet = format!("{packet:02x?}"), + "Failed to parse ping request, so cannot determine correct nagle length!", + ); std::process::exit(GENERATE_NAGLE_FAILURE); } }; info!( + id = "dgswfp::sata_wal::update_connection_read_write", read_size = parsed_data.command_info().user().0, write_size = parsed_data.command_info().user().1, "Updating Connection Read/Write Size", @@ -407,29 +375,12 @@ fn get_wal(wal_path: &Path) -> WriteAheadLog { match WriteAheadLog::new(wal_path.to_path_buf()) { Ok(wal) => wal, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - ?cause, - id = "dgswfp::generate::cannot_open_wal", - wal.path = %wal_path.display(), - "Failed to create a WAL to write!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("cannot open and generate wal"), - [ - cause.into(), - miette!( - "The wal path we would've written to is: {}", - wal_path.display(), - ), - ] - .into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::generate::cannot_open_wal", + wal.path = %wal_path.display(), + "Failed to create a WAL to write!", + ); std::process::exit(GENERATE_CANT_CREATE_WAL); } diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/utils.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/utils.rs index 236b939..d920f40 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/commands/utils.rs +++ b/cmd/dbg-generate-sata-wal-from-pcap/src/commands/utils.rs @@ -1,15 +1,10 @@ //! Utilities that are common across multiple commands. -use crate::{ - SHOULD_LOG_JSON, - exit_codes::{ - ARGV_PCAP_DOES_NOT_EXIST, ARGV_PCAP_PATH_NOT_UTF8, UTILS_CANNOT_SPAWN_TSHARK, - UTILS_TSHARK_READ_FAILURE, - }, - utils::add_context_to, +use crate::exit_codes::{ + ARGV_PCAP_DOES_NOT_EXIST, ARGV_PCAP_PATH_NOT_UTF8, UTILS_CANNOT_SPAWN_TSHARK, + UTILS_TSHARK_READ_FAILURE, }; use bytes::{BufMut, Bytes, BytesMut}; -use miette::miette; use rtshark::{Metadata as RtMetadata, RTShark, RTSharkBuilder}; use std::{iter::Iterator, path::Path}; use tracing::{debug, error}; @@ -17,49 +12,22 @@ use tracing::{debug, error}; /// Validate that the PCAP file exists, and is stored on a UTF-8 path. pub fn validate_pcap_path_constraints(pcap_path: &Path) -> String { if !pcap_path.exists() || !pcap_path.is_file() { - if SHOULD_LOG_JSON() { - error!( - id = "dgswfp::utils::no_source_pcap", - pcap.path = %pcap_path.display(), - "Source PCAP is not an existing file, cannot parse!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("cannot parse a PCAP that is not an existing file"), - [miette!( - "Please ensure the PCAP location you specified is correct: {}", - pcap_path.display(), - )] - .into_iter(), - ), - ); - } + error!( + id = "dgswfp::utils::no_source_pcap", + pcap.path = %pcap_path.display(), + "Source PCAP is not an existing file, cannot parse!", + ); std::process::exit(ARGV_PCAP_DOES_NOT_EXIST); } let Some(existing_path) = pcap_path.to_str() else { - if SHOULD_LOG_JSON() { - error!( - id = "dgswfp::utils::pcap_path_not_utf8", - pcap.path = %pcap_path.display(), - "Source PCAP path must be representable as a UTF-8 string!", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("cannot parse PCAP whose path is not fully UTF-8!"), - [miette!( - "Please move the PCAP file into a UTF-8 compatible path: {}", - pcap_path.display(), - )] - .into_iter(), - ), - ); - } + error!( + id = "dgswfp::utils::pcap_path_not_utf8", + pcap.path = %pcap_path.display(), + help = "Please move the file into a path that is fully UTF-8", + "Source PCAP path must be representable as a UTF-8 string!", + ); std::process::exit(ARGV_PCAP_PATH_NOT_UTF8); }; @@ -98,21 +66,12 @@ impl PacketsWithDataOnPort { { Ok(builder) => builder, Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "dgswfp::utils::pcap_spawn_failure", - pcap.path = pcap, - "failed to spawn tshark, and read from PCAP/PCAPNG.", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to spawn TSHARK, and read from PCAP/PCAPNG."), - [miette!("{cause:?}")].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::utils::pcap_spawn_failure", + pcap.path = pcap, + "failed to spawn tshark, and read from PCAP/PCAPNG.", + ); std::process::exit(UTILS_CANNOT_SPAWN_TSHARK); } @@ -139,7 +98,10 @@ impl Iterator for PacketsWithDataOnPort { Ok(Some(pkt)) => { // Just cause we have a packet doesn't mean it can be used... let Some(tcp_layer) = pkt.layer_name("tcp") else { - debug!("packet is missing TCP layer! skipping..."); + debug!( + id = "dgswfp::utils::no_tcp_layer", + "packet is missing TCP layer! skipping...", + ); continue; }; @@ -147,19 +109,28 @@ impl Iterator for PacketsWithDataOnPort { .metadata("tcp.srcport") .and_then(|val| val.value().parse::().ok()) else { - debug!("packet is missing `tcp.srcport`"); + debug!( + id = "dgswfp::utils::no_tcp_source_port", + "packet is missing `tcp.srcport`", + ); continue; }; let Some(dstport) = tcp_layer .metadata("tcp.dstport") .and_then(|val| val.value().parse::().ok()) else { - debug!("packet is missing `tcp.dstport`"); + debug!( + id = "dgswfp::utils::no_tcp_dest_port", + "packet is missing `tcp.dstport`", + ); continue; }; if srcport != self.port && dstport != self.port { - debug!("packet is not incoming to the correct port"); + debug!( + id = "dgswfp::utils::not_correct_tcp_port", + "packet is not incoming to the correct port", + ); continue; } let is_request = dstport == self.port; @@ -168,7 +139,10 @@ impl Iterator for PacketsWithDataOnPort { .metadata("tcp.stream") .and_then(|val| val.value().parse::().ok()) else { - debug!("packet is missing `tcp.stream`"); + debug!( + id = "dgswfp::utils::no_tcp_stream", + "packet is missing `tcp.stream`", + ); continue; }; let Some(payload) = tcp_layer @@ -176,7 +150,10 @@ impl Iterator for PacketsWithDataOnPort { .map(RtMetadata::raw_value) .map(string_to_hex_bytes) else { - debug!("packet is missing `tcp.payload`"); + debug!( + id = "dgswfp::utils::no_tcp_payload", + "packet is missing `tcp.payload`", + ); continue; }; @@ -187,20 +164,11 @@ impl Iterator for PacketsWithDataOnPort { return None; } Err(cause) => { - if SHOULD_LOG_JSON() { - error!( - id = "dgswfp::utils::pcap_read_failure", - "failed to read from pcap", - ); - } else { - error!( - "\n{:?}", - add_context_to( - miette!("Failed to read data from the PCAP!"), - [miette!("{cause:?}")].into_iter(), - ), - ); - } + error!( + ?cause, + id = "dgswfp::utils::pcap_read_failure", + "failed to read from pcap", + ); std::process::exit(UTILS_TSHARK_READ_FAILURE); } diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/main.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/main.rs index 88ec191..887c687 100644 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/main.rs +++ b/cmd/dbg-generate-sata-wal-from-pcap/src/main.rs @@ -1,7 +1,6 @@ pub mod commands; pub mod exit_codes; pub mod knobs; -pub mod utils; use crate::{ commands::{handle_generate, handle_help, handle_padlog}, @@ -13,34 +12,21 @@ use crate::{ cli::{CliArguments, Subcommands}, env::USE_JSON_OUTPUT, }, - utils::add_context_to, }; -use clap::{Error as ClapError, Parser, error::ErrorKind as ClapErrorKind}; -use log::install_logging_handlers; -use miette::{IntoDiagnostic, miette}; +use clap::{Parser, error::ErrorKind as ClapErrorKind}; +use rm_lisa::{ + display::{SuperConsole, SuperConsoleFlushGuard, renderers::JSONConsoleRenderer}, + initialize_logging, initialize_with_console, +}; +use std::{ + io::{Stderr, Stdout}, + sync::Arc, +}; use tracing::{error, info}; -/// Whether or not we're logging in JSON. -static mut USE_JSON: bool = false; - -/// Whether or not we should log in JSON. -/// -/// Wrapper around the "unsafe" static mutable. This is guaranteed to be -/// safe as it's initialized as the very first thing to be used in the -/// program, and guaranteed to not change after that. -#[allow(non_snake_case)] -#[inline] -#[must_use] -pub fn SHOULD_LOG_JSON() -> bool { - unsafe { USE_JSON } -} - #[tokio::main] async fn main() { - let (argv, use_json) = bootstrap_cli(); - unsafe { - USE_JSON = use_json; - } + let (argv, _log_guard) = bootstrap_cli(); if argv.help || argv.commands.is_none() || matches!(argv.commands, Some(Subcommands::Help {})) { let should_error = !argv.help && argv.commands.is_none(); @@ -53,19 +39,11 @@ async fn main() { } let Some(sub_command) = argv.commands else { - if use_json { - error!( - id = "dgswfp::help::internal", - cause = "Didn't call help even when subcommands was none?" - ); - } else { - error!( - "\n{:?}", - miette!( - "internal error: Failed to specify a single command, and didn't call `help` handler?" - ), - ); - } + error!( + id = "dgswfp::help::internal", + cause = "internal error: Failed to specify a single command, and didn't call `help` handler?" + ); + std::process::exit(SHOULD_NEVER_HAPPEN_FAILURE); }; @@ -89,7 +67,7 @@ async fn main() { } } -fn bootstrap_cli() -> (CliArguments, bool) { +fn bootstrap_cli() -> (CliArguments, SuperConsoleFlushGuard) { let args_opt = CliArguments::try_parse(); let use_json_cli = args_opt.as_ref().map_or_else( @@ -111,63 +89,63 @@ fn bootstrap_cli() -> (CliArguments, bool) { ); let use_json = *USE_JSON_OUTPUT || use_json_cli; - if let Err(cause) = install_logging_handlers(use_json) { - // We have to use a custom panic script here, because logging isn't setup yet. - if use_json { - println!( - r#"{{"id": "dgswfp::logging::install_failure", "inner_display_error": "{}", "message": "Failed to install the logging handlers!"}}"#, - format!("{cause:?}").replace('"', "\\\"") - ); - } else { - println!("Failed to install the logging handler to setup logging:\n{cause:?}"); + let guard: SuperConsoleFlushGuard; + if use_json { + match initialize_with_console(SuperConsole::new_preselected_renderers( + "dgswfp", + Arc::new(JSONConsoleRenderer::new()), + Arc::new(JSONConsoleRenderer::new()), + )) { + Ok(console) => { + guard = SuperConsoleFlushGuard::new(console); + } + Err(cause) => { + println!( + r#"{{"id": "dgswfp::logging::install_failure", "inner_display_error": "{}", "message": "Failed to install the logging handlers!"}}"#, + format!("{cause:?}") + .replace('"', "\\\"") + .replace('\n', " ") + ); + + std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); + } + } + } else { + match initialize_logging("dgswfp") { + Ok(console) => { + guard = SuperConsoleFlushGuard::new(console); + } + Err(cause) => { + // We have to use a custom panic script here, because logging isn't setup yet. + println!("Failed to install the logging handler to setup logging:\n{cause:?}"); + std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); + } } - std::process::exit(LOGGING_HANDLER_INSTALL_FAILURE); } match args_opt { - Ok(args) => (args, use_json), + Ok(args) => (args, guard), Err(cause) => { if cause.kind() == ClapErrorKind::DisplayVersion { - if use_json { - info!( - id = "dgswfp::cli::print_version", - version = format!( - "{} ({})", - format!("{}", cause.render()).trim(), - option_env!("DGSWFP_BUILD").unwrap_or("unknown") - ), - ); - } else { - info!( - "{}", - format!( - "{} ({})", - format!("{}", cause.render()).trim(), - option_env!("DGSWFP_BUILD").unwrap_or("unknown") - ), - ); - } + info!( + id = "dgswfp::cli::print_version", + version = format!( + "{} ({})", + format!("{}", cause.render()).trim(), + option_env!("DGSWFP_BUILD").unwrap_or("unknown") + ), + ); std::process::exit(0); } - if use_json { - error!( - id = "dgswfp::cli::arg_parse_failure", - error.kind = %cause.kind(), - error.context = ?cause.context().map(|(kind, value)| format!("{kind}: {value}")).collect::>(), - error.rendered = %cause.render(), - "Failed parsing CLI arguments" - ); - } else { - error!( - "\n{:?}", - add_context_to( - Err::<(), ClapError>(cause).into_diagnostic().unwrap_err(), - [miette!("Failed parsing CLI arguments!")].into_iter(), - ), - ); - } + error!( + id = "dgswfp::cli::arg_parse_failure", + error.kind = %cause.kind(), + error.context = ?cause.context().map(|(kind, value)| format!("{kind}: {value}")).collect::>(), + error.rendered = %cause.render(), + "Failed parsing CLI arguments" + ); std::process::exit(ARGV_PARSE_FAILURE); } diff --git a/cmd/dbg-generate-sata-wal-from-pcap/src/utils.rs b/cmd/dbg-generate-sata-wal-from-pcap/src/utils.rs deleted file mode 100644 index 57da3a1..0000000 --- a/cmd/dbg-generate-sata-wal-from-pcap/src/utils.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! Utility functions that don't have one place that they should live. - -use miette::Report; - -/// Add context to a specific error, where you can have like a list of -/// suggestions. -/// -/// NOTE: we cannot reassign a reports severity, so your last items severity -/// is where the real severity gets taken. -pub fn add_context_to( - original_error: Report, - suggestions: impl DoubleEndedIterator, -) -> Report { - let mut latest_error: Option = None; - - for suggestion in suggestions.rev() { - if let Some(last_error) = latest_error { - latest_error = Some(last_error.wrap_err(suggestion)); - } else { - latest_error = Some(suggestion); - } - } - - if let Some(latest) = latest_error { - latest.wrap_err(original_error) - } else { - original_error - } -} diff --git a/cmd/mionparamspace/Cargo.toml b/cmd/mionparamspace/Cargo.toml index 7a8cab5..f2caa86 100644 --- a/cmd/mionparamspace/Cargo.toml +++ b/cmd/mionparamspace/Cargo.toml @@ -11,6 +11,4 @@ publish = false [dependencies] cat-dev = { default-features = false, features = ["clients"], path = "../../pkg/cat-dev" } -time.workspace = true tokio.workspace = true - diff --git a/cmd/mionps/Cargo.toml b/cmd/mionps/Cargo.toml index 2f4f7cb..ffa40ad 100644 --- a/cmd/mionps/Cargo.toml +++ b/cmd/mionps/Cargo.toml @@ -10,6 +10,6 @@ version.workspace = true publish = false [dependencies] +chrono.workspace = true cat-dev = { default-features = false, features = ["clients"], path = "../../pkg/cat-dev" } -time.workspace = true tokio.workspace = true diff --git a/cmd/mionps/src/mionps_log.rs b/cmd/mionps/src/mionps_log.rs index 18e877c..6476967 100644 --- a/cmd/mionps/src/mionps_log.rs +++ b/cmd/mionps/src/mionps_log.rs @@ -1,9 +1,8 @@ //! Log statements to match the legacy output of mionps. +use chrono::prelude::*; use std::net::Ipv4Addr; -use time::OffsetDateTime; - /// Create a logging hook to use when we're about to call connect with TCP. pub fn create_session_logging_hook(verbose: bool) -> impl Fn(u128) + Clone + Send + 'static { if verbose { @@ -121,15 +120,15 @@ pub fn log_error(error_msg: &str) { /// Log a verbose message which includes a timestamp. pub fn log_verbose(message: &str) { - let current_time = OffsetDateTime::now_utc(); + let current_time = Utc::now(); println!( "mionps: VERBOSE: [{:02}/{:02}/{:04} {:02}:{:02}:{:02}.{:03}] {message}", - u8::from(current_time.month()), + u8::try_from(current_time.month()).unwrap_or(u8::MAX), current_time.day(), current_time.year(), current_time.hour(), current_time.minute(), current_time.second(), - current_time.millisecond(), + current_time.timestamp_subsec_millis(), ); } diff --git a/cmd/setbridgeconfig/src/main.rs b/cmd/setbridgeconfig/src/main.rs index 754b22c..08598ec 100644 --- a/cmd/setbridgeconfig/src/main.rs +++ b/cmd/setbridgeconfig/src/main.rs @@ -111,22 +111,22 @@ fn protect_bridge( bridge_name: &str, bridge_ip: Ipv4Addr, ) { - if let Some((existing_bridge_ip, _is_default)) = state.get_bridge(bridge_name) { - if existing_bridge_ip != Some(bridge_ip) { - if is_protecting { - println!( - "\nERROR : The specified IP address {bridge_ip} conflicts with an existing entry !" - ); - std::process::exit(-1); - } else if let Some(ex_bridge_ip) = existing_bridge_ip { - println!( - "\nWARNING : IP address for bridge \"{bridge_name}\" updated from {ex_bridge_ip} to {bridge_ip}" - ); - } else { - println!( - "\nWARNING : IP address for bridge \"{bridge_name}\" updated from to {bridge_ip}" - ); - } + if let Some((existing_bridge_ip, _is_default)) = state.get_bridge(bridge_name) + && existing_bridge_ip != Some(bridge_ip) + { + if is_protecting { + println!( + "\nERROR : The specified IP address {bridge_ip} conflicts with an existing entry !" + ); + std::process::exit(-1); + } else if let Some(ex_bridge_ip) = existing_bridge_ip { + println!( + "\nWARNING : IP address for bridge \"{bridge_name}\" updated from {ex_bridge_ip} to {bridge_ip}" + ); + } else { + println!( + "\nWARNING : IP address for bridge \"{bridge_name}\" updated from to {bridge_ip}" + ); } } } diff --git a/pkg/cat-dev/Cargo.toml b/pkg/cat-dev/Cargo.toml index aeeb2ae..1484d05 100644 --- a/pkg/cat-dev/Cargo.toml +++ b/pkg/cat-dev/Cargo.toml @@ -16,43 +16,43 @@ servers = ["bitflags", "local-ip-address", "rand", "sysinfo", "tower", "wide"] [dependencies] aes = "^0.8.4" -bitflags = { version = "^2.9.1", default-features = false, optional = true } +bitflags = { version = "^2.9.4", default-features = false, optional = true } bytes.workspace = true cipher = { version = "^0.4.4", features = ["alloc", "block-padding"] } configparser = "^3.1.0" ecb = "^0.1.2" fnv.workspace = true -form_urlencoded = { version = "^1.2.1", optional = true } +form_urlencoded = { version = "^1.2.2", optional = true } futures.workspace = true local-ip-address = { version = "^0.6.5", optional = true } mac_address = { optional = true, workspace = true } miette.workspace = true network-interface = { optional = true, workspace = true } pin-project-lite = { version = "^0.2.16", optional = true } -reqwest = { version = "^0.12.22", default-features = false, features=["charset", "macos-system-configuration"], optional = true } -rand = { version = "^0.9.0", optional = true } -scc = "^2.3.4" -sysinfo = { version = "^0.35.1", default-features = false, features=["disk", "linux-tmpfs"], optional = true } -thiserror = "^2.0.12" +reqwest = { version = "^0.12.23", default-features = false, features=["charset", "macos-system-configuration"], optional = true } +rand = { version = "^0.9.2", optional = true } +scc = "^3.2.0" +sysinfo = { version = "^0.37.1", default-features = false, features=["disk", "linux-tmpfs"], optional = true } +thiserror = "^2.0.17" tracing.workspace = true tokio.workspace = true -tokio-util = { version = "^0.7.15", default-features = false, features = ["codec"] } +tokio-util = { version = "^0.7.16", default-features = false, features = ["codec"] } tower = { version = "^0.5.2", default-features = false, features = ["util", "make"], optional = true } valuable.workspace = true walkdir = "^2.5.0" wide = { version = "^0.7.33", optional = true } -whoami = "^1.6.0" +whoami = "^1.6.1" [target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "macos"))'.dependencies] libc = { version = "^0.2", optional = true } [target.'cfg(target_os = "windows")'.dependencies] -windows = { version = "^0.61.3", default-features = false, features=["Win32_Devices_Communication", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Registry", "Win32_System_Threading", "std"], optional = true } +windows = { version = "^0.62.1", default-features = false, features=["Win32_Devices_Communication", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Registry", "Win32_System_Threading", "std"], optional = true } [dev-dependencies] -tempfile = "^3.20.0" +tempfile = "^3.23.0" [package.metadata.docs.rs] features = ["clients", "scientists", "serial", "servers"] rustc-args = ["--cfg", "tokio_unstable", "--cfg", "tracing_unstable"] -rustdoc-args = ["--cfg", "tokio_unstable", "--cfg", "tracing_unstable"] \ No newline at end of file +rustdoc-args = ["--cfg", "tokio_unstable", "--cfg", "tracing_unstable"] diff --git a/pkg/cat-dev/src/fsemul/atapi/server.rs b/pkg/cat-dev/src/fsemul/atapi/server.rs index d23941a..ea2bd5e 100644 --- a/pkg/cat-dev/src/fsemul/atapi/server.rs +++ b/pkg/cat-dev/src/fsemul/atapi/server.rs @@ -74,11 +74,17 @@ pub async fn create_atapi_server( trace_during_debug, ) .await?; - server.layer_initial_service( - ServiceBuilder::new() - .layer(RequestIDLayer) - .layer(StreamIDLayer), - ); + if trace_during_debug { + server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("atapi".to_owned())) + .layer(StreamIDLayer), + ); + } else { + server.layer_initial_service( + ServiceBuilder::new().layer(RequestIDLayer::new("atapi".to_owned())), + ); + } server.set_chunk_output_at_size(if fully_disable_chunk_override { None diff --git a/pkg/cat-dev/src/fsemul/host_filesystem.rs b/pkg/cat-dev/src/fsemul/host_filesystem.rs index c7c2d79..e33bb5a 100644 --- a/pkg/cat-dev/src/fsemul/host_filesystem.rs +++ b/pkg/cat-dev/src/fsemul/host_filesystem.rs @@ -249,7 +249,8 @@ impl HostFilesystem { }; self.open_file_handles - .insert(final_fd, (fd, md.len(), path.clone(), stream_owner)) + .insert_async(final_fd, (fd, md.len(), path.clone(), stream_owner)) + .await .map_err(|_| IOError::other("somehow got duplicate fd?"))?; Ok(final_fd) } @@ -261,7 +262,7 @@ impl HostFilesystem { &self, fd: i32, for_stream: Option, - ) -> Option), RandomState>> { + ) -> Option), RandomState>> { self.open_file_handles .get_async(&fd) .await @@ -400,11 +401,11 @@ impl HostFilesystem { /// If we cannot close our file handle when our ref count reaches 0, or if /// the file isn't open at all. pub async fn close_file(&self, fd: i32, for_stream: Option) { - if let Some(entry) = self.open_file_handles.get_async(&fd).await { - if !Self::allow_file_access(&entry, for_stream) { - // Don't allow streams to close other streams files. - return; - } + if let Some(entry) = self.open_file_handles.get_async(&fd).await + && !Self::allow_file_access(&entry, for_stream) + { + // Don't allow streams to close other streams files. + return; } self.open_file_handles.remove_async(&fd).await; @@ -427,7 +428,7 @@ impl HostFilesystem { let fake_fd = FOLDER_FD.fetch_add(1, AtomicOrdering::SeqCst); self.open_folder_handles - .insert(fake_fd, (dhandle, 0, false, path.clone(), for_stream)) + .insert_sync(fake_fd, (dhandle, 0, false, path.clone(), for_stream)) .map_err(|_| IOError::other("OS returned duplicate fd?"))?; Ok(fake_fd) } @@ -531,10 +532,10 @@ impl HostFilesystem { /// If we cannot close our folder handle when our ref count reaches 0, or if /// the folder isn't open at all. pub async fn close_folder(&self, fd: i32, for_stream: Option) { - if let Some(real_entry) = self.open_folder_handles.get_async(&fd).await { - if !Self::allow_folder_access(&real_entry, for_stream) { - return; - } + if let Some(real_entry) = self.open_folder_handles.get_async(&fd).await + && !Self::allow_folder_access(&real_entry, for_stream) + { + return; } self.open_folder_handles.remove_async(&fd).await; @@ -1283,21 +1284,21 @@ impl HostFilesystem { let mut wii_file = File::create(wii_path).await.map_err(FSError::IO)?; wii_file .write_all( - br#" - - + br#" + + 00570069006900000000000000000000000000000000 - 0 - 1 - - - 18 - 0 - 0 - 0 - 0 - + 0 + 1 + + + 18 + 0 + 0 + 0 + 0 + "#, ) .await @@ -1350,7 +1351,7 @@ impl HostFilesystem { &["data", "mlc", "usr", "import"], &["data", "mlc", "usr", "title"], ] { - _ = set.insert(Self::join_many(cafe_dir, cafe_sub_paths)); + _ = set.insert_sync(Self::join_many(cafe_dir, cafe_sub_paths)); } set @@ -1376,12 +1377,14 @@ impl Valuable for HostFilesystem { fn visit(&self, visitor: &mut dyn Visit) { let mut values = HashMap::with_capacity(self.open_file_handles.len()); - self.open_file_handles.scan(|k, v| { + self.open_file_handles.iter_sync(|k, v| { values.insert(*k, format!("{}", v.2.display())); + true }); let mut folder_values = HashMap::with_capacity(self.open_folder_handles.len()); - self.open_folder_handles.scan(|k, v| { + self.open_folder_handles.iter_sync(|k, v| { folder_values.insert(*k, format!("{}", v.3.display())); + true }); visitor.visit_named_fields(&NamedValues::new( @@ -1847,7 +1850,7 @@ mod unit_tests { .await .expect("Failed opening a file that doesn't exist with a create flag?"); assert!( - fs.open_file_handles.len() == 1 && fs.open_file_handles.get(&fd).is_some(), + fs.open_file_handles.len() == 1 && fs.open_file_handles.get_sync(&fd).is_some(), "Open file wasn't in open files list!", ); fs.close_file(fd, None).await; diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/client.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/client.rs index 3c3de61..60dcb8d 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/client.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/client.rs @@ -312,8 +312,9 @@ impl SataClient { let typed_response = match query_type { SataQueryType::FileCount => SataQueryResponse::try_from_small(bytes)?, SataQueryType::FileDetails => SataQueryResponse::try_from_fd_info(bytes)?, - SataQueryType::FreeDiskSpace => SataQueryResponse::try_from_large(bytes)?, - SataQueryType::SizeOfFolder => SataQueryResponse::try_from_large(bytes)?, + SataQueryType::FreeDiskSpace | SataQueryType::SizeOfFolder => { + SataQueryResponse::try_from_large(bytes)? + } }; if let SataQueryResponse::ErrorCode(ec) = typed_response { return Err(NetworkParseError::ErrorCode(ec).into()); @@ -910,11 +911,11 @@ impl SataClientFileHandle<'_> { fn calculate_ideal_block_size_count(amount: usize) -> (u32, u32) { if amount < 512 { (u32::try_from(amount).expect("unreachable()"), 1) - } else if amount % 512 == 0 { + } else if amount.is_multiple_of(512) { (512, u32::try_from(amount / 512).unwrap_or(u32::MAX)) } else { let mut count = 511; - while amount % count != 0 { + while !amount.is_multiple_of(count) { count -= 1; } diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/connection_flags.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/connection_flags.rs index 10958f1..0c986b5 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/connection_flags.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/connection_flags.rs @@ -170,7 +170,7 @@ where } fn call(&mut self, mut req: Request) -> Self::Future { - if let Some(flags) = SATA_CONNECTION_FLAGS.get(&req.stream_id()) { + if let Some(flags) = SATA_CONNECTION_FLAGS.get_sync(&req.stream_id()) { req.extensions_mut().insert(flags.clone()); } diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/create_folder.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/create_folder.rs index bb82a05..e9b8177 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/create_folder.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/create_folder.rs @@ -52,16 +52,16 @@ pub async fn handle_create_folder( return SataResponse::new(state.pid(), request_header, SataResultCode::error(FS_ERROR)); } - if !fs_location.resolved_path().exists() { - if let Err(cause) = create_dir_all(fs_location.resolved_path()).await { - error!( - ?cause, - path = %fs_location.resolved_path().display(), - "Failed to create directory for PCFS.", - ); - - return SataResponse::new(state.pid(), request_header, SataResultCode::error(FS_ERROR)); - } + if !fs_location.resolved_path().exists() + && let Err(cause) = create_dir_all(fs_location.resolved_path()).await + { + error!( + ?cause, + path = %fs_location.resolved_path().display(), + "Failed to create directory for PCFS.", + ); + + return SataResponse::new(state.pid(), request_header, SataResultCode::error(FS_ERROR)); } // Don't set folders as read-only. diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/info_by_query.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/info_by_query.rs index 5d7fdf4..1229cb6 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/info_by_query.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/info_by_query.rs @@ -169,12 +169,11 @@ fn handle_disk_space( .unwrap_or_else(|_| mount_point.to_path_buf()), ) { let mut should_insert = true; - if let Some(other_potential_source) = disk_holding_path { - if other_potential_source.mount_point().components().count() + if let Some(other_potential_source) = disk_holding_path + && other_potential_source.mount_point().components().count() > potential_disk.mount_point().components().count() - { - should_insert = false; - } + { + should_insert = false; } if should_insert { _ = disk_holding_path.insert(potential_disk); diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/mod.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/mod.rs index df3e4da..5935cb4 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/mod.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/mod.rs @@ -184,7 +184,7 @@ pub async fn pcfs_sata_server( ) .await?; - let mut wal = match sata_wal_location { + let wal = match sata_wal_location { Some(p) => WriteAheadLog::new(p).ok(), None => None, }; @@ -209,22 +209,7 @@ pub async fn pcfs_sata_server( server.layer_on_stream_end(WALEndStreamLayer(w.clone()))?; } - if let Some(w) = wal.take() { - server.layer_initial_service( - ServiceBuilder::new() - .layer(RequestIDLayer) - .layer(StreamIDLayer) - .layer(SataConnectionFlagsLayer) - .layer(WALMessageLayer(w)), - ); - } else { - server.layer_initial_service( - ServiceBuilder::new() - .layer(RequestIDLayer) - .layer(StreamIDLayer) - .layer(SataConnectionFlagsLayer), - ); - } + create_initial_server_layer(&mut server, wal, trace_during_debug); server.set_chunk_output_at_size(if fully_disable_chunk_override { None @@ -242,6 +227,44 @@ pub async fn pcfs_sata_server( Ok(server) } +fn create_initial_server_layer( + server: &mut TCPServer, + mut wal: Option, + trace_during_debug: bool, +) { + if let Some(w) = wal.take() { + if trace_during_debug { + server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("sata".to_owned())) + .layer(StreamIDLayer) + .layer(SataConnectionFlagsLayer) + .layer(WALMessageLayer(w)), + ); + } else { + server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("sata".to_owned())) + .layer(SataConnectionFlagsLayer) + .layer(WALMessageLayer(w)), + ); + } + } else if trace_during_debug { + server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("sata".to_owned())) + .layer(StreamIDLayer) + .layer(SataConnectionFlagsLayer), + ); + } else { + server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("sata".to_owned())) + .layer(SataConnectionFlagsLayer), + ); + } +} + async fn unknown_packet_handler(Body(request): Body) -> Response { if let Ok(req) = SataRequest::::parse_opaque(request.clone()) { warn!( diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/read_file.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/read_file.rs index fd4b9e7..c21523d 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/read_file.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/read_file.rs @@ -38,25 +38,24 @@ pub async fn handle_read_file( let ffio_enabled = flags.ffio_enabled(); let mut buffer_grew = flags.ffio_buffer_should_have_grown(); - if packet.should_move() { - if let Err(cause) = packet + if packet.should_move() + && let Err(cause) = packet .move_to_pointer() .do_move(&fs, handle, Some(stream.to_raw())) .await - { - debug!( - ?cause, - packet.fd = handle, - packet.typ = "PCFSSrvReadFile", - "Failed to move file to a specific pointer!", - ); - - if ffio_enabled { - return Ok(construct_ffio_error(FS_ERROR)); - } - - todo!("Implement non-FFIO support."); + { + debug!( + ?cause, + packet.fd = handle, + packet.typ = "PCFSSrvReadFile", + "Failed to move file to a specific pointer!", + ); + + if ffio_enabled { + return Ok(construct_ffio_error(FS_ERROR)); } + + todo!("Implement non-FFIO support."); } let Some(file_size) = fs.file_length(handle, Some(stream.to_raw())).await else { diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/wal/mod.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/wal/mod.rs index d312a84..170bb1e 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/wal/mod.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/wal/mod.rs @@ -300,31 +300,31 @@ async fn process_wal(mut stream: BoundedReceiver, path: Pa let resp = mapper::WaitingResponse::parse(conn_flags, &req, data); match resp { mapper::WaitingResponse::OpenFile(fdres) => { - if let Ok(fd) = fdres.result() { - if let mapper::WaitingRequest::OpenFile(path, _) = req { - fd_map_mut.insert(fd, path); - } + if let Ok(fd) = fdres.result() + && let mapper::WaitingRequest::OpenFile(path, _) = req + { + fd_map_mut.insert(fd, path); } } mapper::WaitingResponse::OpenFolder(fdres) => { - if let Ok(fd) = fdres.result() { - if let mapper::WaitingRequest::OpenFolder(path) = req { - folder_map_mut.insert(fd, path); - } + if let Ok(fd) = fdres.result() + && let mapper::WaitingRequest::OpenFolder(path) = req + { + folder_map_mut.insert(fd, path); } } mapper::WaitingResponse::CloseFile(rc) => { - if rc.0 == 0 { - if let mapper::WaitingRequest::CloseFile(fd, _) = req { - fd_map_mut.remove(&fd); - } + if rc.0 == 0 + && let mapper::WaitingRequest::CloseFile(fd, _) = req + { + fd_map_mut.remove(&fd); } } mapper::WaitingResponse::CloseFolder(rc) => { - if rc.0 == 0 { - if let mapper::WaitingRequest::CloseFolder(fd, _) = req { - folder_map_mut.remove(&fd); - } + if rc.0 == 0 + && let mapper::WaitingRequest::CloseFolder(fd, _) = req + { + folder_map_mut.remove(&fd); } } mapper::WaitingResponse::Pong(ffio, csr) => { diff --git a/pkg/cat-dev/src/fsemul/pcfs/sata/server/write_file.rs b/pkg/cat-dev/src/fsemul/pcfs/sata/server/write_file.rs index 4ef9786..1f87716 100644 --- a/pkg/cat-dev/src/fsemul/pcfs/sata/server/write_file.rs +++ b/pkg/cat-dev/src/fsemul/pcfs/sata/server/write_file.rs @@ -37,8 +37,8 @@ pub async fn handle_write_file( let request_header = request.header().clone(); let packet = request.body(); - if packet.should_move() { - if let Err(cause) = packet + if packet.should_move() + && let Err(cause) = packet .move_to_pointer() .do_move( state.host_filesystem(), @@ -46,20 +46,19 @@ pub async fn handle_write_file( Some(req.stream_id()), ) .await - { - debug!( - ?cause, - packet.fd = packet.file_descriptor(), - packet.typ = "PCFSSrvWriteFile", - "Failed to seek file!", - ); + { + debug!( + ?cause, + packet.fd = packet.file_descriptor(), + packet.typ = "PCFSSrvWriteFile", + "Failed to seek file!", + ); - return Ok(SataResponse::new( - state.pid(), - request_header, - SataResultCode::error(FS_ERROR), - )); - } + return Ok(SataResponse::new( + state.pid(), + request_header, + SataResultCode::error(FS_ERROR), + )); } if flags.ffio_enabled() { diff --git a/pkg/cat-dev/src/fsemul/sdio/proto/read.rs b/pkg/cat-dev/src/fsemul/sdio/proto/read.rs index 0c98af1..66bb8a8 100644 --- a/pkg/cat-dev/src/fsemul/sdio/proto/read.rs +++ b/pkg/cat-dev/src/fsemul/sdio/proto/read.rs @@ -29,7 +29,7 @@ impl SdioControlReadRequest { /// - If the channel's first byte is greater than or equal to `0xC` when /// encoded to little endian. pub fn new(lba: u32, blocks: u32, channel: u32) -> Result { - if lba < SDIO_BLOCK_SIZE_AS_U32 || lba % SDIO_BLOCK_SIZE_AS_U32 != 0 { + if lba < SDIO_BLOCK_SIZE_AS_U32 || !lba.is_multiple_of(SDIO_BLOCK_SIZE_AS_U32) { return Err(SDIOAPIError::InvalidLBA(lba)); } let as_bytes = channel.to_le_bytes(); @@ -88,7 +88,7 @@ impl SdioControlReadRequest { /// - If the LBA address is not a possible block address (must be divisble by /// [`SDIO_BLOCK_SIZE_AS_U32`]). pub fn set_lba(&mut self, new_lba: u32) -> Result<(), SDIOAPIError> { - if new_lba < SDIO_BLOCK_SIZE_AS_U32 || new_lba % SDIO_BLOCK_SIZE_AS_U32 != 0 { + if new_lba < SDIO_BLOCK_SIZE_AS_U32 || !new_lba.is_multiple_of(SDIO_BLOCK_SIZE_AS_U32) { return Err(SDIOAPIError::InvalidLBA(new_lba)); } diff --git a/pkg/cat-dev/src/fsemul/sdio/proto/write.rs b/pkg/cat-dev/src/fsemul/sdio/proto/write.rs index e43d401..81a40a9 100644 --- a/pkg/cat-dev/src/fsemul/sdio/proto/write.rs +++ b/pkg/cat-dev/src/fsemul/sdio/proto/write.rs @@ -29,7 +29,7 @@ impl SdioControlWriteRequest { /// - If the channel's first byte is greater than or equal to `0xC` when /// encoded to little endian. pub fn new(lba: u32, blocks: u32, channel: u32) -> Result { - if lba < SDIO_BLOCK_SIZE_AS_U32 || lba % SDIO_BLOCK_SIZE_AS_U32 != 0 { + if lba < SDIO_BLOCK_SIZE_AS_U32 || !lba.is_multiple_of(SDIO_BLOCK_SIZE_AS_U32) { return Err(SDIOAPIError::InvalidLBA(lba)); } let as_bytes = channel.to_le_bytes(); @@ -88,7 +88,7 @@ impl SdioControlWriteRequest { /// - If the LBA address is not a possible block address (must be divisble by /// [`SDIO_BLOCK_SIZE_AS_U32`]). pub fn set_lba(&mut self, new_lba: u32) -> Result<(), SDIOAPIError> { - if new_lba < SDIO_BLOCK_SIZE_AS_U32 || new_lba % SDIO_BLOCK_SIZE_AS_U32 != 0 { + if new_lba < SDIO_BLOCK_SIZE_AS_U32 || !new_lba.is_multiple_of(SDIO_BLOCK_SIZE_AS_U32) { return Err(SDIOAPIError::InvalidLBA(new_lba)); } diff --git a/pkg/cat-dev/src/fsemul/sdio/server/message.rs b/pkg/cat-dev/src/fsemul/sdio/server/message.rs index c51978f..03fe9f4 100644 --- a/pkg/cat-dev/src/fsemul/sdio/server/message.rs +++ b/pkg/cat-dev/src/fsemul/sdio/server/message.rs @@ -60,10 +60,7 @@ fn process_log_messages(printf_buff: &mut String) { // Ignore empty newlines they try to send. if !actual_line.trim().is_empty() { - info!( - sdio.data.printf = %actual_line.trim(), - "Received SDIO message.", - ); + info!("{}", actual_line.trim(),); } } while let Some(line_ending) = printf_buff.find('\n') { @@ -73,10 +70,7 @@ fn process_log_messages(printf_buff: &mut String) { // Ignore empty newlines they try to send. if !actual_line.trim().is_empty() { - info!( - sdio.data.printf = %actual_line.trim(), - "Received SDIO message.", - ); + info!("{}", actual_line.trim(),); } } while let Some(line_ending) = printf_buff.find('\r') { @@ -86,10 +80,7 @@ fn process_log_messages(printf_buff: &mut String) { // Ignore empty newlines they try to send. if !actual_line.trim().is_empty() { - info!( - sdio.data.printf = %actual_line.trim(), - "Received SDIO message.", - ); + info!("{}", actual_line.trim(),); } } diff --git a/pkg/cat-dev/src/fsemul/sdio/server/mod.rs b/pkg/cat-dev/src/fsemul/sdio/server/mod.rs index db975db..44cb219 100644 --- a/pkg/cat-dev/src/fsemul/sdio/server/mod.rs +++ b/pkg/cat-dev/src/fsemul/sdio/server/mod.rs @@ -114,11 +114,17 @@ pub async fn sdio_server( .await?; control_server.set_on_stream_begin(on_sdio_stream_begin)?; control_server.set_on_stream_end(on_sdio_stream_end)?; - control_server.layer_initial_service( - ServiceBuilder::new() - .layer(RequestIDLayer) - .layer(StreamIDLayer), - ); + if trace_during_debug { + control_server.layer_initial_service( + ServiceBuilder::new() + .layer(RequestIDLayer::new("sdio".to_owned())) + .layer(StreamIDLayer), + ); + } else { + control_server.layer_initial_service( + ServiceBuilder::new().layer(RequestIDLayer::new("sdio".to_owned())), + ); + } // We are still communicating with a slowdown... control_server.set_cat_dev_slowdown(control_server.state().cat_dev_slowdown); control_server.set_chunk_output_at_size(chunk_frd); diff --git a/pkg/cat-dev/src/fsemul/sdio/server/read.rs b/pkg/cat-dev/src/fsemul/sdio/server/read.rs index 6af8e01..6ce5407 100644 --- a/pkg/cat-dev/src/fsemul/sdio/server/read.rs +++ b/pkg/cat-dev/src/fsemul/sdio/server/read.rs @@ -34,7 +34,7 @@ pub(super) async fn handle_read_request( stream_id: StreamID, Body(request): Body, ) -> Result<(), CatBridgeError> { - let Some(data_stream) = SDIO_DATA_STREAMS.get(&stream_id.to_raw()) else { + let Some(data_stream) = SDIO_DATA_STREAMS.get_async(&stream_id.to_raw()).await else { return Err(SDIONetworkError::DataStreamMissing(stream_id.to_raw()).into()); }; diff --git a/pkg/cat-dev/src/mion/discovery.rs b/pkg/cat-dev/src/mion/discovery.rs index 4045e38..ab627b8 100644 --- a/pkg/cat-dev/src/mion/discovery.rs +++ b/pkg/cat-dev/src/mion/discovery.rs @@ -430,15 +430,11 @@ where break; }; - if let Some(filter_mac) = find_by_mac.as_ref() { - if *filter_mac == identity.mac_address() { - return Ok(Some(identity)); - } + if let Some(filter_mac) = find_by_mac.as_ref() && *filter_mac == identity.mac_address() { + return Ok(Some(identity)); } - if let Some(filter_name) = find_by_name.as_ref() { - if filter_name == identity.name() { - return Ok(Some(identity)); - } + if let Some(filter_name) = find_by_name.as_ref() && filter_name == identity.name() { + return Ok(Some(identity)); } } () = sleep(early_scan_timeout.unwrap_or(Duration::from_secs(MION_ANNOUNCE_TIMEOUT_SECONDS * 2))) => { diff --git a/pkg/cat-dev/src/mion/proto/cgis/setup.rs b/pkg/cat-dev/src/mion/proto/cgis/setup.rs index 6cc894d..b57ce78 100644 --- a/pkg/cat-dev/src/mion/proto/cgis/setup.rs +++ b/pkg/cat-dev/src/mion/proto/cgis/setup.rs @@ -199,13 +199,13 @@ impl SetupParameters { Self { static_ip_address: Ipv4Addr::new(192, 168, 0, 1), subnet_mask: Ipv4Addr::new(255, 255, 255, 0), - default_gateway: Ipv4Addr::new(0, 0, 0, 0), + default_gateway: Ipv4Addr::UNSPECIFIED, dhcp: true, dns: false, - primary_dns_server: Ipv4Addr::new(0, 0, 0, 0), - secondary_dns_server: Ipv4Addr::new(0, 0, 0, 0), + primary_dns_server: Ipv4Addr::UNSPECIFIED, + secondary_dns_server: Ipv4Addr::UNSPECIFIED, jumbo_frame: true, - host_pc_ip: Ipv4Addr::new(0, 0, 0, 0), + host_pc_ip: Ipv4Addr::UNSPECIFIED, bank_size: CatDevBankSize::Blank, hdd_bank_no: 0, atapi_emulator_port: 7974, diff --git a/pkg/cat-dev/src/mion/proto/images/mod.rs b/pkg/cat-dev/src/mion/proto/images/mod.rs new file mode 100644 index 0000000..27a75cb --- /dev/null +++ b/pkg/cat-dev/src/mion/proto/images/mod.rs @@ -0,0 +1,39 @@ +//! Protocols, and types specifically related to "IMAGES", or Disc Images for +//! dealing with the MION. + +use std::fmt::{Display, Formatter, Result as FmtResult}; +use valuable::Valuable; + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Valuable)] +pub enum MIONDiscImageType { + WUMAD, + WUM, + Unknown(u8), +} +impl Display for MIONDiscImageType { + fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult { + match *self { + Self::WUMAD => write!(fmt, "WUMAD"), + Self::WUM => write!(fmt, "WUM/UNSET"), + Self::Unknown(val) => write!(fmt, "Unk({val})"), + } + } +} +impl From for MIONDiscImageType { + fn from(value: u8) -> Self { + match value { + 255 => MIONDiscImageType::WUM, + 254 => MIONDiscImageType::WUMAD, + num => MIONDiscImageType::Unknown(num), + } + } +} +impl From for u8 { + fn from(value: MIONDiscImageType) -> u8 { + match value { + MIONDiscImageType::WUM => 255, + MIONDiscImageType::WUMAD => 254, + MIONDiscImageType::Unknown(num) => num, + } + } +} diff --git a/pkg/cat-dev/src/mion/proto/mod.rs b/pkg/cat-dev/src/mion/proto/mod.rs index d6ffeb8..19dce6c 100644 --- a/pkg/cat-dev/src/mion/proto/mod.rs +++ b/pkg/cat-dev/src/mion/proto/mod.rs @@ -24,6 +24,7 @@ pub mod cgis; pub mod control; +pub mod images; pub mod parameter; /// The port the MION uses for 'control' commands. diff --git a/pkg/cat-dev/src/mion/proto/parameter/well_known.rs b/pkg/cat-dev/src/mion/proto/parameter/well_known.rs index 27a6ddd..eb07d12 100644 --- a/pkg/cat-dev/src/mion/proto/parameter/well_known.rs +++ b/pkg/cat-dev/src/mion/proto/parameter/well_known.rs @@ -1,7 +1,9 @@ //! Parameters that are well known, and can be referred to by their name //! rather than just their index. -use crate::mion::proto::{control::MIONBootType, parameter::MIONParameterAPIError}; +use crate::mion::proto::{ + control::MIONBootType, images::MIONDiscImageType, parameter::MIONParameterAPIError, +}; use bytes::Bytes; use valuable::{Fields, NamedField, NamedValues, StructDef, Structable, Valuable, Value, Visit}; @@ -55,10 +57,10 @@ impl TryFrom for ParameterLocationSpecification { /// Attempt to get the index of a marater based on a name #[must_use] pub fn index_from_parameter_name(name: &str) -> Option { - if let Ok(number) = name.parse::() { - if number < 512 { - return Some(number); - } + if let Ok(number) = name.parse::() + && number < 512 + { + return Some(number); } match name { @@ -69,6 +71,17 @@ pub fn index_from_parameter_name(name: &str) -> Option { | "sdk minor version" | "minor-version" | "minor_version" | "minor version" | "minor" => Some(4), "sdk-misc" | "sdk_misc" | "sdk misc" | "sdk-misc-version" | "sdk_misc_version" | "sdk misc version" | "misc-version" | "misc_version" | "misc version" | "misc" => Some(5), + "bank-0" | "bank_0" | "bank 0" => Some(100), + "bank-1" | "bank_1" | "bank 1" => Some(101), + "bank-2" | "bank_2" | "bank 2" => Some(102), + "bank-3" | "bank_3" | "bank 3" => Some(103), + "bank-4" | "bank_4" | "bank 4" => Some(104), + "bank-5" | "bank_5" | "bank 5" => Some(105), + "bank-6" | "bank_6" | "bank 6" => Some(106), + "bank-7" | "bank_7" | "bank 7" => Some(107), + "bank-8" | "bank_8" | "bank 8" => Some(108), + "bank-9" | "bank_9" | "bank 9" => Some(109), + "bank-10" | "bank_10" | "bank 10" => Some(110), _ => None, } } @@ -95,6 +108,11 @@ pub fn validate_value_at_index( MIONBootType::NAND | MIONBootType::PCFS | MIONBootType::DUAL => true, MIONBootType::Unk(_) => false, }, + // Bank types + // + // 255 == WUM/WUD/Unset + // 254 == WUMAD + 100..=110 => byte_value >= 254, // Has no specific validation rule we know of. _ => true, } @@ -105,9 +123,23 @@ const PARAMETER_DUMP_FIELDS: &[NamedField<'static>] = &[ NamedField::new("SdkMajor"), NamedField::new("SdkMinor"), NamedField::new("SdkMisc"), + NamedField::new("Bank0"), + NamedField::new("Bank1"), + NamedField::new("Bank2"), + NamedField::new("Bank3"), + NamedField::new("Bank4"), + NamedField::new("Bank5"), + NamedField::new("Bank6"), + NamedField::new("Bank7"), + NamedField::new("Bank8"), + NamedField::new("Bank9"), + NamedField::new("Bank10"), NamedField::new("UnknownParameters"), ]; -const KNOWN_INDEXES: &[usize] = &[2_usize, 3_usize, 4_usize, 5_usize]; +const KNOWN_INDEXES: &[usize] = &[ + 2_usize, 3_usize, 4_usize, 5_usize, 100_usize, 101_usize, 102_usize, 103_usize, 104_usize, + 105_usize, 106_usize, 107_usize, 108_usize, 109_usize, 110_usize, +]; pub struct ValuableParameterDump<'value>(pub &'value Bytes); impl Structable for ValuableParameterDump<'_> { fn definition(&self) -> StructDef<'_> { @@ -138,6 +170,17 @@ impl Valuable for ValuableParameterDump<'_> { Valuable::as_value(&self.0[KNOWN_INDEXES[1]]), Valuable::as_value(&self.0[KNOWN_INDEXES[2]]), Valuable::as_value(&self.0[KNOWN_INDEXES[3]]), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[4]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[5]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[6]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[7]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[8]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[9]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[10]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[11]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[12]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[13]])), + Valuable::as_value(&MIONDiscImageType::from(self.0[KNOWN_INDEXES[14]])), Valuable::as_value(&unknown_params), ], )); diff --git a/pkg/cat-dev/src/net/additions/request_id.rs b/pkg/cat-dev/src/net/additions/request_id.rs index 6da76b9..20fdf1d 100644 --- a/pkg/cat-dev/src/net/additions/request_id.rs +++ b/pkg/cat-dev/src/net/additions/request_id.rs @@ -28,7 +28,7 @@ use tracing::{ field::valuable, instrument::{Instrument, Instrumented}, }; -use valuable::{Fields, NamedField, NamedValues, StructDef, Structable, Valuable, Value, Visit}; +use valuable::{Valuable, Value, Visit}; #[derive(Clone, PartialEq, Eq)] pub struct RequestID(Arc); @@ -113,26 +113,25 @@ impl Deref for RequestID { } } -const REQUEST_ID_FIELDS: &[NamedField<'static>] = &[NamedField::new("id")]; - -impl Structable for RequestID { - fn definition(&self) -> StructDef<'_> { - StructDef::new_static("RequestID", Fields::Named(REQUEST_ID_FIELDS)) - } -} - impl Valuable for RequestID { fn as_value(&self) -> Value<'_> { - Value::Structable(self) + Value::String(self.0.as_str()) } fn visit(&self, visitor: &mut dyn Visit) { - visitor.visit_named_fields(&NamedValues::new(REQUEST_ID_FIELDS, &[self.0.as_value()])); + visitor.visit_value(self.as_value()); } } #[derive(Clone, Debug)] -pub struct RequestIDLayer; +pub struct RequestIDLayer(String); + +impl RequestIDLayer { + #[must_use] + pub const fn new(service_name: String) -> Self { + Self(service_name) + } +} impl Layer for RequestIDLayer where @@ -141,13 +140,17 @@ where type Service = LayeredRequestID; fn layer(&self, inner: Layered) -> Self::Service { - LayeredRequestID { inner } + LayeredRequestID { + inner, + service_name: self.0.clone(), + } } } #[derive(Clone)] pub struct LayeredRequestID { inner: Layered, + service_name: String, } impl Service> @@ -178,9 +181,10 @@ where let req_id = RequestID::generate(); let span = error_span!( - parent: parent_span, - "WithRequestID", - request.id = valuable(&req_id), + parent: parent_span, + "WithRequestID", + lisa.subsystem = %self.service_name, + request.id = valuable(&req_id), ); req.extensions_mut().insert::(req_id); req.extensions_mut().insert::>(span.id()); diff --git a/pkg/cat-dev/src/net/client/tcp.rs b/pkg/cat-dev/src/net/client/tcp.rs index fe94311..acd9521 100644 --- a/pkg/cat-dev/src/net/client/tcp.rs +++ b/pkg/cat-dev/src/net/client/tcp.rs @@ -815,8 +815,9 @@ impl TCPClient { let mut ids = FnvHashSet::default(); self.streams - .scan_async(|stream_id, _stream| { + .iter_async(|stream_id, _stream| { ids.insert(*stream_id); + true }) .await; @@ -865,8 +866,9 @@ impl TCPClient { } else { let mut ids = FnvHashSet::default(); self.streams - .scan_async(|stream_id, _stream| { + .iter_async(|stream_id, _stream| { ids.insert(*stream_id); + true }) .await; @@ -900,8 +902,9 @@ impl TCPClient { ) -> FnvHashMap> { let mut ids = FnvHashSet::default(); self.streams - .scan_async(|stream_id, _stream| { + .iter_async(|stream_id, _stream| { ids.insert(*stream_id); + true }) .await; @@ -931,8 +934,9 @@ impl TCPClient { let mut ids = FnvHashSet::default(); self.streams - .scan_async(|stream_id, _stream| { + .iter_async(|stream_id, _stream| { ids.insert(*stream_id); + true }) .await; @@ -1118,8 +1122,8 @@ impl TCPClient { ) -> Result { tcp_stream.set_nodelay(true).map_err(NetworkError::IO)?; - if let Some(mut handle) = on_stream_begin_handler { - if !handle + if let Some(mut handle) = on_stream_begin_handler + && !handle .call(RequestStreamEvent::new_with_state( send_channel.clone(), *remote_address, @@ -1127,10 +1131,9 @@ impl TCPClient { (), )) .await? - { - trace!("handler failed on stream begin hook"); - return Ok(true); - } + { + trace!("handler failed on stream begin hook"); + return Ok(true); } Ok(false) @@ -1360,10 +1363,10 @@ impl TCPClient { ) -> (u64, Option) { if let Some(mut stream) = self.streams.get_async(&stream_id).await { while let Some((opt_req_id, response)) = stream.response_channel_mut().recv().await { - if let Some(got_req_id) = opt_req_id { - if got_req_id == request_id { - return (stream_id, Some(response)); - } + if let Some(got_req_id) = opt_req_id + && got_req_id == request_id + { + return (stream_id, Some(response)); } } @@ -1381,11 +1384,11 @@ impl TCPClient { return Err(CommonNetClientNetworkError::NotConnectedToServer); } - if !self.streams.contains(&active_sid) { + if !self.streams.contains_async(&active_sid).await { let mut oldest_stream = None; self.streams - .scan_async(|stream_id, stream| { + .iter_async(|stream_id, stream| { if let Some((_strm_id, strm_created_at)) = oldest_stream { if stream.opened_at() < strm_created_at { _ = oldest_stream.insert((*stream_id, stream.opened_at())); @@ -1393,6 +1396,7 @@ impl TCPClient { } else { _ = oldest_stream.insert((*stream_id, stream.opened_at())); } + true }) .await; } @@ -1461,8 +1465,9 @@ impl Valuable for TCPClient { fn visit(&self, visitor: &mut dyn Visit) { let mut valuable_map = FnvHashMap::default(); - self.streams.scan(|stream_id, stream| { + self.streams.iter_sync(|stream_id, stream| { valuable_map.insert(*stream_id, stream.to_valuable()); + true }); visitor.visit_named_fields(&NamedValues::new( diff --git a/pkg/cat-dev/src/net/server/tcp.rs b/pkg/cat-dev/src/net/server/tcp.rs index 98e3f5b..2cde32d 100644 --- a/pkg/cat-dev/src/net/server/tcp.rs +++ b/pkg/cat-dev/src/net/server/tcp.rs @@ -318,8 +318,9 @@ impl TCPServer { let mut ids = FnvHashSet::default(); // Scan all senders at a Point-in-Time.. OUT_OF_BAND_SENDERS - .scan_async(|key, _value| { + .iter_async(|key, _value| { ids.insert(*key); + true }) .await; @@ -962,8 +963,8 @@ impl TCPServer { .upsert_async(stream_id, send_channel.clone()) .await; - if let Some(mut handle) = on_stream_begin_handler { - if !handle + if let Some(mut handle) = on_stream_begin_handler + && !handle .call(ResponseStreamEvent::new_with_state( send_channel.clone(), *source_address, @@ -971,10 +972,9 @@ impl TCPServer { state.clone(), )) .await? - { - trace!("handler failed on stream begin hook"); - return Ok(true); - } + { + trace!("handler failed on stream begin hook"); + return Ok(true); } Ok(false) @@ -999,40 +999,40 @@ impl TCPServer { Ok(true) } ResponseStreamMessage::Response(resp) => { - if let Some(body) = resp.body() { - if !body.is_empty() { - let messages = if let Some(size) = chunk_output_on_size { - body.chunks(size) - .map(Bytes::copy_from_slice) - .collect::>() - } else { - vec![body.clone()] - }; - - for message in messages { - #[cfg(debug_assertions)] - if trace_io { - debug!( - body.hex = format!("{message:02x?}"), - body.str = String::from_utf8_lossy(&message).to_string(), - "cat-dev-trace-output-tcp-server", - ); - } - - let mut full_response = message.clone(); - if let Some(post) = post_hook { - full_response = block_in_place(|| post(stream_id, full_response)); - } - if let Some(slowdown_ms) = cat_dev_slowdown { - sleep(slowdown_ms).await; - } - - tcp_stream.writable().await.map_err(NetworkError::IO)?; - tcp_stream - .write_all(&full_response) - .await - .map_err(NetworkError::IO)?; + if let Some(body) = resp.body() + && !body.is_empty() + { + let messages = if let Some(size) = chunk_output_on_size { + body.chunks(size) + .map(Bytes::copy_from_slice) + .collect::>() + } else { + vec![body.clone()] + }; + + for message in messages { + #[cfg(debug_assertions)] + if trace_io { + debug!( + body.hex = format!("{message:02x?}"), + body.str = String::from_utf8_lossy(&message).to_string(), + "cat-dev-trace-output-tcp-server", + ); + } + + let mut full_response = message.clone(); + if let Some(post) = post_hook { + full_response = block_in_place(|| post(stream_id, full_response)); } + if let Some(slowdown_ms) = cat_dev_slowdown { + sleep(slowdown_ms).await; + } + + tcp_stream.writable().await.map_err(NetworkError::IO)?; + tcp_stream + .write_all(&full_response) + .await + .map_err(NetworkError::IO)?; } } diff --git a/pkg/cat-dev/src/serial/underlying/sys/unix.rs b/pkg/cat-dev/src/serial/underlying/sys/unix.rs index 481339e..2d3855a 100644 --- a/pkg/cat-dev/src/serial/underlying/sys/unix.rs +++ b/pkg/cat-dev/src/serial/underlying/sys/unix.rs @@ -443,10 +443,9 @@ impl RawSyncSerialPort { // They have a file called `device/driver_override` set to "(null)". if let Ok(driver_override) = std::fs::read(entry.path().join("device/driver_override")) + && driver_override == b"(null)\n" { - if driver_override == b"(null)\n" { - return None; - } + return None; } Some(dev_path) diff --git a/pkg/log/Cargo.toml b/pkg/log/Cargo.toml deleted file mode 100644 index fb9f59f..0000000 --- a/pkg/log/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "log" -description = "A small wrapper around logging initialization." -authors.workspace = true -edition.workspace = true -license.workspace = true -repository.workspace = true -version.workspace = true -# This is just our logging crate, don't publish it. -publish = false - -[dependencies] -console-subscriber = { version = "^0.4.1", default-features = false, features = ["env-filter", "parking_lot"] } -miette.workspace = true -tracing.workspace = true -tracing-error = "^0.2.1" -tracing-subscriber = { version = "^0.3.19", features = ["env-filter", "json", "valuable"] } \ No newline at end of file diff --git a/pkg/log/README.md b/pkg/log/README.md deleted file mode 100644 index d8a4ec2..0000000 --- a/pkg/log/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# Log # - -A very small micro crate that handles setting up all of our logging -infrastructure. Even though this is just one function we don't really want to -paste it in every single little crate, and what if we ever want to change it? - -***NOTE: this logging infrastructure is only available on new tools. e.g. this is -present in `bridgectl`, but NOT `findbridge`. This is to keep re-implementations -having the same output format as the original tools.*** - -So we create just a single crate that really only handles the one thing. -Logging. Simple, and easy. If you want to modify the logging level, simply set -the environment variable `SPRIG_LOGGING` to the logging level/filter you -would like for logging in sprig components. If you're curious about what -logging levels are allowed, [please read the documentation of the tracing crate](https://docs.rs/tracing/latest/tracing/struct.Level.html#impl-Level). - -As hinted too you can specify more than levels, and instead specify full on -filters with the environment variable `SPRIG_LOGGING`, while you can read -the very deep documentation [HERE](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives) -the general idea is you can set logging for _specific_ crates, and by -separating them with commas. For example: `cdb=debug,error`, this will turn the -logging level of any log lines coming from the Cat Dev-Bridge library will be -"DEBUG", but anything besides the Cat Dev-Bridge library will be at "ERROR". -These filters should make it possible to get pretty much any level of debugging -you want from the tools without too much trouble. - -## Debugging with Tokio-Console ## - -*note: most users will not need this, you should really only reach for this -if you're asked too, or you know you want to dig into asynchronous things -tokio-console can help with.* - -Sometimes debugging asynchronous tasks can be particularly tough. What happens -if the command just freezes because we're waiting on something, and we're not -sure what's happening? What happens if we just wanna see a top like view of -everything that's running? Well this is where [tokio-console](https://github.com/tokio-rs/console#tokio-console) -comes in. It is an external tool, that you can use to get a `top` like view -of the asynchronous tasks that are running within our single process. - -To enable this simply set the environment variable `SPRIG_TOKIO_CONSOLE_ADDR` -to the network address you want the console to listen on. From this point on -tokio-console will automatically be spun up and run. - -***If you are setting `SPRIG_LOGGING`, you must be sure to turn tokio/runtime up -to trace for tokio-console to work! If you don't specify it, it will -automatically be handled.*** - -## Using in Other Parts of the Codebase ## - -There are really two parts of logging within the codebase, displaying logs, and -actually writing log statements to be logged somewhere. This crate should only -be used in the *first case*. For command line tools that are ***not*** -re-implementations (where we need to match the output 1-to-1), you would take a -dependency on the `log` crate like: `log = { path = "../../pkg/log" }`, and -then call: `log::install_logging_handlers()?;` as the first line in your `main` -function. - -When you need to write a statement to output log data, you should instead use -the [`tracing`] crate. With the helpers like [`tracing::info!`], -[`tracing::error!`], etc. You also can use the other tracing macros to create -things like spans which you may be used to in other languages. diff --git a/pkg/log/src/lib.rs b/pkg/log/src/lib.rs deleted file mode 100644 index 4880c16..0000000 --- a/pkg/log/src/lib.rs +++ /dev/null @@ -1,155 +0,0 @@ -#![doc = include_str!("../README.md")] - -use miette::{Context, IntoDiagnostic, Result, miette}; -use std::{ - env::var as env_var, - net::SocketAddr, - sync::{LazyLock, Mutex}, -}; -use tracing::debug; -use tracing_error::ErrorLayer; -use tracing_subscriber::{ - EnvFilter, fmt::layer as tracing_fmt_layer, prelude::*, registry as subscriber_registry, -}; - -/// Check if we have actually initialized logging before. -static HAS_INITIALIZED_LOGGING: LazyLock> = LazyLock::new(|| Mutex::new(false)); - -/// Determine if our logger will use ANSI escape codes. -/// -/// Although i wish we had support for better detection than this, this is -/// unfortunately inhereted from tracing-subscriber which is significantly -/// better at like everything else. -/// -/// So even though it kinda stinks here, it's worth the tradeoff. This line is -/// copied directly from tracing subscriber: -/// -#[must_use] -pub fn will_ansi() -> bool { - env_var("NO_COLOR").map_or(true, |v| v.is_empty()) -} - -/// Install all the logging configuration needed for an application. -/// -/// This should only ever be called as the very first part of `main`, and -/// nowhere else. If you try to call it elsewhere, you'll just get am error. -/// -/// See the tracing docs for logging for more information: -/// -/// -/// It should be noted this is also what starts up 'tokio-console' level -/// filtering as that hooks very heavily into tracing data. -/// -/// # Panics -/// -/// If you've requested `tokio-console`, and it can't spawn the server. -/// -/// # Errors -/// -/// If we fail to install all of the logging handlers. -pub fn install_logging_handlers(use_json: bool) -> Result<()> { - { - let mut locked_init = HAS_INITIALIZED_LOGGING - .lock() - .expect("Intall logging handlers called with poisioned mutex?"); - if *locked_init { - return Err(miette!("Logging has already been initialized!")); - } - *locked_init = true; - } - let explicit_level = env_var("SPRIG_LOGGING").ok(); - let console_address = env_var("SPRIG_TOKIO_CONSOLE_ADDR").ok(); - - // tokio-console requires tokio/runtime to be at the trace level. - let filter_layer = EnvFilter::try_from_default_env().or_else(|_| { - EnvFilter::try_new(if let Some(el) = explicit_level { - el - } else if console_address.is_some() { - "info,tokio=trace,runtime=trace".to_owned() - } else { - "info".to_owned() - }) - .into_diagnostic() - })?; - let registry = subscriber_registry().with(filter_layer); - - if let Some(addr) = console_address.as_ref() { - let console_uri = addr - .parse::() - .into_diagnostic() - .wrap_err("Failed to parse `SPRIG_TOKIO_CONSOLE_ADDR` as an address to listen on!")?; - - if use_json { - registry - .with( - tracing_fmt_layer() - .with_target(false) - .json() - .with_current_span(false) - .with_span_list(true), - ) - .with(ErrorLayer::default()) - .with( - console_subscriber::ConsoleLayer::builder() - .enable_self_trace(true) - .server_addr(console_uri) - .spawn(), - ) - .init(); - } else { - registry - .with(tracing_fmt_layer().with_target(true).compact()) - .with(ErrorLayer::default()) - .with( - console_subscriber::ConsoleLayer::builder() - .enable_self_trace(true) - .server_addr(console_uri) - .spawn(), - ) - .init(); - } - } else if use_json { - registry - .with( - tracing_fmt_layer() - .with_target(true) - .json() - .with_current_span(false) - .with_span_list(true), - ) - .with(ErrorLayer::default()) - .init(); - } else { - registry - .with(tracing_fmt_layer().with_target(true).compact()) - .with(ErrorLayer::default()) - .init(); - } - - debug!( - console_enabled = console_address.is_some(), - "tokio-console-status" - ); - Ok(()) -} - -#[cfg(test)] -mod unit_tests { - use super::*; - - #[test] - pub fn cant_install_twice() { - assert!( - install_logging_handlers(true).is_ok(), - "Failed to perform initial install of logging handlers, this should ALWAYS succeed.", - ); - assert!( - install_logging_handlers(false).is_err(), - "Second call to install of logging handlers somehow failed?", - ); - assert!( - install_logging_handlers(true).is_err(), - "Third call to install of logging handlers somehow failed?", - ); - } -}