[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!

upload: add logs for reqwest and improve error logging/handling

note: includes `use` commands which are unneeded rn
this is bc i cant be fucked to remove ones which are needed for the next commit. go fuck urself idc

vielle.dev 2da885ba ebc5618d

verified
Changed files
+281 -101
upload
+235 -13
upload/Cargo.lock
··· 22 22 ] 23 23 24 24 [[package]] 25 + name = "addr2line" 26 + version = "0.25.1" 27 + source = "registry+https://github.com/rust-lang/crates.io-index" 28 + checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b" 29 + dependencies = [ 30 + "gimli", 31 + ] 32 + 33 + [[package]] 25 34 name = "adler2" 26 35 version = "2.0.1" 27 36 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 157 166 version = "0.1.0" 158 167 dependencies = [ 159 168 "clap", 169 + "env_logger", 160 170 "ignore", 161 171 "jacquard", 172 + "lexicons", 173 + "miette", 162 174 "mime_guess", 163 175 "regex", 164 176 "reqwest", 177 + "thiserror 2.0.17", 165 178 "tokio", 166 179 ] 167 180 ··· 176 189 version = "1.5.0" 177 190 source = "registry+https://github.com/rust-lang/crates.io-index" 178 191 checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" 192 + 193 + [[package]] 194 + name = "backtrace" 195 + version = "0.3.76" 196 + source = "registry+https://github.com/rust-lang/crates.io-index" 197 + checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6" 198 + dependencies = [ 199 + "addr2line", 200 + "cfg-if", 201 + "libc", 202 + "miniz_oxide", 203 + "object", 204 + "rustc-demangle", 205 + "windows-link 0.2.1", 206 + ] 207 + 208 + [[package]] 209 + name = "backtrace-ext" 210 + version = "0.2.1" 211 + source = "registry+https://github.com/rust-lang/crates.io-index" 212 + checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" 213 + dependencies = [ 214 + "backtrace", 215 + ] 179 216 180 217 [[package]] 181 218 name = "base-x" ··· 823 860 ] 824 861 825 862 [[package]] 863 + name = "env_filter" 864 + version = "0.1.4" 865 + source = "registry+https://github.com/rust-lang/crates.io-index" 866 + checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" 867 + dependencies = [ 868 + "log", 869 + "regex", 870 + ] 871 + 872 + [[package]] 873 + name = "env_logger" 874 + version = "0.11.8" 875 + source = "registry+https://github.com/rust-lang/crates.io-index" 876 + checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" 877 + dependencies = [ 878 + "anstream", 879 + "anstyle", 880 + "env_filter", 881 + "jiff", 882 + "log", 883 + ] 884 + 885 + [[package]] 826 886 name = "equivalent" 827 887 version = "1.0.2" 828 888 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 934 994 checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" 935 995 936 996 [[package]] 997 + name = "futures-macro" 998 + version = "0.3.31" 999 + source = "registry+https://github.com/rust-lang/crates.io-index" 1000 + checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" 1001 + dependencies = [ 1002 + "proc-macro2", 1003 + "quote", 1004 + "syn 2.0.106", 1005 + ] 1006 + 1007 + [[package]] 937 1008 name = "futures-sink" 938 1009 version = "0.3.31" 939 1010 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 952 1023 checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" 953 1024 dependencies = [ 954 1025 "futures-core", 1026 + "futures-io", 1027 + "futures-macro", 1028 + "futures-sink", 955 1029 "futures-task", 1030 + "memchr", 956 1031 "pin-project-lite", 957 1032 "pin-utils", 958 1033 "slab", ··· 995 1070 "wasip2", 996 1071 "wasm-bindgen", 997 1072 ] 1073 + 1074 + [[package]] 1075 + name = "gimli" 1076 + version = "0.32.3" 1077 + source = "registry+https://github.com/rust-lang/crates.io-index" 1078 + checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7" 998 1079 999 1080 [[package]] 1000 1081 name = "globset" ··· 1494 1575 ] 1495 1576 1496 1577 [[package]] 1578 + name = "is_ci" 1579 + version = "1.2.0" 1580 + source = "registry+https://github.com/rust-lang/crates.io-index" 1581 + checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" 1582 + 1583 + [[package]] 1497 1584 name = "is_terminal_polyfill" 1498 1585 version = "1.70.1" 1499 1586 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1507 1594 1508 1595 [[package]] 1509 1596 name = "jacquard" 1510 - version = "0.5.3" 1597 + version = "0.5.4" 1511 1598 source = "registry+https://github.com/rust-lang/crates.io-index" 1512 - checksum = "bf257386e29370eb7387093736d59f2aeda3ac692a37481c7201bc5f9cc82fae" 1599 + checksum = "c9f7e9e2fb15b8e526c8f44ba197ba8b4174858d05522f088d1ff8de0ce02836" 1513 1600 dependencies = [ 1514 1601 "bon", 1515 1602 "bytes", ··· 1539 1626 1540 1627 [[package]] 1541 1628 name = "jacquard-api" 1542 - version = "0.5.3" 1629 + version = "0.5.5" 1543 1630 source = "registry+https://github.com/rust-lang/crates.io-index" 1544 - checksum = "e67619aa60467ee687633e5face5743835e5f9d8e57c387a8d830cfd2ba8d2c8" 1631 + checksum = "eef8307959cc031759816d8e44a3c4db5dd184eedec07431579877a8c4741b80" 1545 1632 dependencies = [ 1546 1633 "bon", 1547 1634 "bytes", ··· 1554 1641 1555 1642 [[package]] 1556 1643 name = "jacquard-common" 1557 - version = "0.5.3" 1644 + version = "0.5.4" 1558 1645 source = "registry+https://github.com/rust-lang/crates.io-index" 1559 - checksum = "8b1c05d479eee46004ba3ec495e7802b7c02cc429396aeb7296a558b9cb6e6ce" 1646 + checksum = "cf91dfa4ade1ca83c9afccee4ece7ed72b6607a0853d88623958d4e7c5382eb3" 1560 1647 dependencies = [ 1561 1648 "base64 0.22.1", 1562 1649 "bon", ··· 1590 1677 1591 1678 [[package]] 1592 1679 name = "jacquard-derive" 1593 - version = "0.5.3" 1680 + version = "0.5.4" 1594 1681 source = "registry+https://github.com/rust-lang/crates.io-index" 1595 - checksum = "aadace50223141e60d16e26a28c8c8a9b647f291814986010234cf1c130367ab" 1682 + checksum = "4f7db8498da87d842297b169a0080eed751bce173c56626b5fa71261fe72f804" 1596 1683 dependencies = [ 1597 1684 "proc-macro2", 1598 1685 "quote", ··· 1626 1713 1627 1714 [[package]] 1628 1715 name = "jacquard-oauth" 1629 - version = "0.5.3" 1716 + version = "0.5.4" 1630 1717 source = "registry+https://github.com/rust-lang/crates.io-index" 1631 - checksum = "597e74c6697a449e834936dde22c30165f0f2da0c38b42ec599173b58d73a098" 1718 + checksum = "0c583fb0f634654b51d390809f4dc5b08087d34c155b33d89b36475f6e6b1428" 1632 1719 dependencies = [ 1633 1720 "base64 0.22.1", 1634 1721 "bytes", ··· 1660 1747 ] 1661 1748 1662 1749 [[package]] 1750 + name = "jiff" 1751 + version = "0.2.15" 1752 + source = "registry+https://github.com/rust-lang/crates.io-index" 1753 + checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" 1754 + dependencies = [ 1755 + "jiff-static", 1756 + "log", 1757 + "portable-atomic", 1758 + "portable-atomic-util", 1759 + "serde", 1760 + ] 1761 + 1762 + [[package]] 1763 + name = "jiff-static" 1764 + version = "0.2.15" 1765 + source = "registry+https://github.com/rust-lang/crates.io-index" 1766 + checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" 1767 + dependencies = [ 1768 + "proc-macro2", 1769 + "quote", 1770 + "syn 2.0.106", 1771 + ] 1772 + 1773 + [[package]] 1663 1774 name = "jni" 1664 1775 version = "0.21.1" 1665 1776 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1875 1986 source = "registry+https://github.com/rust-lang/crates.io-index" 1876 1987 checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" 1877 1988 dependencies = [ 1989 + "backtrace", 1990 + "backtrace-ext", 1878 1991 "cfg-if", 1879 1992 "miette-derive", 1880 - "unicode-width", 1993 + "owo-colors", 1994 + "supports-color", 1995 + "supports-hyperlinks", 1996 + "supports-unicode", 1997 + "terminal_size", 1998 + "textwrap", 1999 + "unicode-width 0.1.14", 1881 2000 ] 1882 2001 1883 2002 [[package]] ··· 2090 2209 ] 2091 2210 2092 2211 [[package]] 2212 + name = "object" 2213 + version = "0.37.3" 2214 + source = "registry+https://github.com/rust-lang/crates.io-index" 2215 + checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" 2216 + dependencies = [ 2217 + "memchr", 2218 + ] 2219 + 2220 + [[package]] 2093 2221 name = "once_cell" 2094 2222 version = "1.21.3" 2095 2223 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2170 2298 ] 2171 2299 2172 2300 [[package]] 2301 + name = "owo-colors" 2302 + version = "4.2.3" 2303 + source = "registry+https://github.com/rust-lang/crates.io-index" 2304 + checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" 2305 + 2306 + [[package]] 2173 2307 name = "p256" 2174 2308 version = "0.13.2" 2175 2309 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2267 2401 version = "0.3.32" 2268 2402 source = "registry+https://github.com/rust-lang/crates.io-index" 2269 2403 checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" 2404 + 2405 + [[package]] 2406 + name = "portable-atomic" 2407 + version = "1.11.1" 2408 + source = "registry+https://github.com/rust-lang/crates.io-index" 2409 + checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" 2410 + 2411 + [[package]] 2412 + name = "portable-atomic-util" 2413 + version = "0.2.4" 2414 + source = "registry+https://github.com/rust-lang/crates.io-index" 2415 + checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" 2416 + dependencies = [ 2417 + "portable-atomic", 2418 + ] 2270 2419 2271 2420 [[package]] 2272 2421 name = "potential_utf" ··· 2585 2734 "url", 2586 2735 "wasm-bindgen", 2587 2736 "wasm-bindgen-futures", 2737 + "wasm-streams", 2588 2738 "web-sys", 2589 2739 "webpki-roots", 2590 2740 ] ··· 2664 2814 ] 2665 2815 2666 2816 [[package]] 2817 + name = "rustc-demangle" 2818 + version = "0.1.26" 2819 + source = "registry+https://github.com/rust-lang/crates.io-index" 2820 + checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" 2821 + 2822 + [[package]] 2667 2823 name = "rustc-hash" 2668 2824 version = "2.1.1" 2669 2825 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2684 2840 2685 2841 [[package]] 2686 2842 name = "rustls" 2687 - version = "0.23.32" 2843 + version = "0.23.33" 2688 2844 source = "registry+https://github.com/rust-lang/crates.io-index" 2689 - checksum = "cd3c25631629d034ce7cd9940adc9d45762d46de2b0f57193c4443b92c6d4d40" 2845 + checksum = "751e04a496ca00bb97a5e043158d23d66b5aabf2e1d5aa2a0aaebb1aafe6f82c" 2690 2846 dependencies = [ 2691 2847 "once_cell", 2692 2848 "ring", ··· 3037 3193 checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 3038 3194 3039 3195 [[package]] 3196 + name = "supports-color" 3197 + version = "3.0.2" 3198 + source = "registry+https://github.com/rust-lang/crates.io-index" 3199 + checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6" 3200 + dependencies = [ 3201 + "is_ci", 3202 + ] 3203 + 3204 + [[package]] 3205 + name = "supports-hyperlinks" 3206 + version = "3.1.0" 3207 + source = "registry+https://github.com/rust-lang/crates.io-index" 3208 + checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b" 3209 + 3210 + [[package]] 3211 + name = "supports-unicode" 3212 + version = "3.0.0" 3213 + source = "registry+https://github.com/rust-lang/crates.io-index" 3214 + checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" 3215 + 3216 + [[package]] 3040 3217 name = "syn" 3041 3218 version = "1.0.109" 3042 3219 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 3113 3290 ] 3114 3291 3115 3292 [[package]] 3293 + name = "terminal_size" 3294 + version = "0.4.3" 3295 + source = "registry+https://github.com/rust-lang/crates.io-index" 3296 + checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" 3297 + dependencies = [ 3298 + "rustix", 3299 + "windows-sys 0.60.2", 3300 + ] 3301 + 3302 + [[package]] 3303 + name = "textwrap" 3304 + version = "0.16.2" 3305 + source = "registry+https://github.com/rust-lang/crates.io-index" 3306 + checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057" 3307 + dependencies = [ 3308 + "unicode-linebreak", 3309 + "unicode-width 0.2.2", 3310 + ] 3311 + 3312 + [[package]] 3116 3313 name = "thiserror" 3117 3314 version = "1.0.69" 3118 3315 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 3401 3598 checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" 3402 3599 3403 3600 [[package]] 3601 + name = "unicode-linebreak" 3602 + version = "0.1.5" 3603 + source = "registry+https://github.com/rust-lang/crates.io-index" 3604 + checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" 3605 + 3606 + [[package]] 3404 3607 name = "unicode-width" 3405 3608 version = "0.1.14" 3406 3609 source = "registry+https://github.com/rust-lang/crates.io-index" 3407 3610 checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" 3611 + 3612 + [[package]] 3613 + name = "unicode-width" 3614 + version = "0.2.2" 3615 + source = "registry+https://github.com/rust-lang/crates.io-index" 3616 + checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" 3408 3617 3409 3618 [[package]] 3410 3619 name = "unsigned-varint" ··· 3564 3773 checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" 3565 3774 dependencies = [ 3566 3775 "unicode-ident", 3776 + ] 3777 + 3778 + [[package]] 3779 + name = "wasm-streams" 3780 + version = "0.4.2" 3781 + source = "registry+https://github.com/rust-lang/crates.io-index" 3782 + checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" 3783 + dependencies = [ 3784 + "futures-util", 3785 + "js-sys", 3786 + "wasm-bindgen", 3787 + "wasm-bindgen-futures", 3788 + "web-sys", 3567 3789 ] 3568 3790 3569 3791 [[package]]
+6 -10
upload/Cargo.toml
··· 8 8 edition = "2024" 9 9 10 10 [dependencies] 11 - # lexicons = { path = "./lexicons" } 11 + lexicons = { path = "./lexicons" } 12 12 clap = { version = "4.5.49", features = ["derive"] } 13 13 ignore = "0.4.23" 14 14 regex = "1.12.2" 15 15 mime_guess = "2.0.5" 16 16 tokio = { version = "1.48.0", features = ["full"] } 17 - jacquard = { version = "0.5.3", features = ["api", "dns"] } 18 - reqwest = { version = "0.12.24", features = [ 19 - "__tls", 20 - "charset", 21 - "default-tls", 22 - "h2", 23 - "http2", 24 - "system-proxy", 25 - ] } 17 + jacquard = "0.5.4" 18 + reqwest = "0.12.24" 19 + env_logger = "0.11.8" 20 + miette = { version = "7.6.0", features = ["derive", "fancy"] } 21 + thiserror = "2.0.17"
+26 -39
upload/src/main.rs
··· 1 1 use clap::{ArgAction, Parser}; 2 + use jacquard::api::com_atproto::repo::apply_writes::{self, ApplyWrites, ApplyWritesWritesItem}; 3 + use jacquard::atproto; 2 4 use jacquard::client::MemorySessionStore; 5 + use jacquard::prelude::XrpcClient; 6 + use jacquard::types::string::{AtStrError, RecordKey, Rkey}; 3 7 use jacquard::{ 4 8 Data, 5 9 api::com_atproto::{self, repo::list_records::ListRecords}, 6 - client::{Agent, AgentSessionExt, credential_session::CredentialSession}, 10 + client::{Agent, credential_session::CredentialSession}, 7 11 cowstr::ToCowStr, 8 12 identity::JacquardResolver, 9 13 types::{ident::AtIdentifier, nsid::Nsid, string::AtprotoStr, uri::Uri}, 10 14 xrpc::XrpcExt, 11 15 }; 16 + use miette::{ErrReport, IntoDiagnostic, Result}; 12 17 use std::{collections::HashMap, fs, path::PathBuf}; 13 18 14 19 use crate::sitemap::{BlobRef, Sitemap, SitemapNode}; ··· 44 49 } 45 50 46 51 #[tokio::main] 47 - async fn main() -> Result<(), ()> { 52 + async fn main() -> Result<(), miette::Error> { 53 + env_logger::init(); 48 54 // get config items 49 55 let config = Config::parse(); 50 56 51 57 // get local site info 52 - let local_sitemap = sitemap::local_sitemap(config.dir, config.all_files, config.git_ignore) 53 - .map_err(|err| { 54 - println!("Sitemap Error: {}", err); 55 - })?; 58 + let local_sitemap = sitemap::local_sitemap(config.dir, config.all_files, config.git_ignore)?; 56 59 57 60 // create session 58 61 let client = JacquardResolver::default(); 59 62 let store = MemorySessionStore::default(); 60 63 let session = CredentialSession::new(store.into(), client.into()); 61 64 62 - let auth = match session 65 + let auth = session 63 66 .login(config.user.into(), config.password.into(), None, None, None) 64 - .await 65 - { 66 - Ok(val) => { 67 - println!("Authenticated {} ({})", val.handle, val.did); 68 - val 69 - } 70 - Err(err) => { 71 - println!("Got error while authenticating:\n{}", err); 72 - return Err(()); 73 - } 74 - }; 67 + .await?; 68 + println!("Authenticated as {}", auth.did); 69 + 75 70 76 71 let agent = Agent::from(session); 77 72 ··· 91 86 let res = agent 92 87 .xrpc(agent.endpoint().await) 93 88 .send::<ListRecords>(&req) 94 - .await 95 - .map_err(|err| { 96 - println!("Error fetching records: {err}"); 97 - })? 98 - .into_output() 99 - .map_err(|err| { 100 - println!("Error fetching records: {err}"); 101 - })?; 89 + .await? 90 + .into_output()?; 102 91 103 92 for record in res.records { 104 93 match record { ··· 132 121 } 133 122 } 134 123 135 - println!("{remote_records:?}"); 136 - 137 124 // upload local site blobs 138 125 let mut new_sitemap: Sitemap = HashMap::new(); 139 126 for (k, v) in local_sitemap { ··· 143 130 panic!("Impossible state") 144 131 } 145 132 }; 146 - let blob = fs::read(blob).map_err(|err| { 147 - println!("FS error: {err}"); 148 - })?; 149 - let res = agent 150 - .upload_blob(blob, v.mime_type.clone().into()) 151 - .await 152 - .map_err(|err| { 153 - println!("Blob upload error: {err}"); 154 - })?; 133 + let blob = fs::read(blob).into_diagnostic()?; 134 + // let res = agent 135 + // .upload_blob(blob, v.mime_type.clone().into()) 136 + // .await?; 137 + 138 + let req = com_atproto::repo::upload_blob::UploadBlob::new() 139 + .body(blob.into()) 140 + .build(); 141 + let res = agent.send(req).await?.into_output()?; 142 + 155 143 new_sitemap.insert( 156 144 k, 157 145 SitemapNode { 158 146 mime_type: v.mime_type, 159 - blob: BlobRef::Remote(res.r#ref), 147 + blob: BlobRef::Remote(res.blob), 160 148 }, 161 149 ); 162 150 } 163 - println!("{:#?}", new_sitemap); 164 151 165 152 // batch delete/upload records 166 153
+14 -39
upload/src/sitemap.rs
··· 1 1 use ignore::WalkBuilder; 2 - use jacquard::types::cid::Cid; 2 + use jacquard::types::blob::Blob; 3 + use miette::Diagnostic; 3 4 use mime_guess::mime; 4 - use std::{collections::HashMap, error::Error, fmt, path::PathBuf}; 5 + use std::{collections::HashMap, path::PathBuf}; 6 + use thiserror::Error; 5 7 6 8 pub type Sitemap = HashMap<String, SitemapNode>; 7 9 ··· 14 16 #[derive(Debug)] 15 17 pub enum BlobRef { 16 18 Local(PathBuf), 17 - Remote(Cid<'static>), 19 + Remote(Blob<'static>), 18 20 } 19 21 20 - #[derive(Debug)] 22 + #[derive(Debug, Error, Diagnostic)] 21 23 pub enum SitemapErr { 22 - IoErr(std::io::Error), 23 - IgnoreErr(ignore::Error), 24 - StripPrefixErr(std::path::StripPrefixError), 24 + #[error("IO error: {}", .0)] 25 + IoErr(#[from] std::io::Error), 26 + #[error("Error finding files: {}", .0)] 27 + IgnoreErr(#[from] ignore::Error), 28 + #[error("Error normalising file paths: {}", .0)] 29 + StripPrefixErr(#[from] std::path::StripPrefixError), 30 + #[error("Found non UTF-8 path")] 25 31 NotUTF8Path, 26 32 } 27 33 28 - impl From<std::io::Error> for SitemapErr { 29 - fn from(value: std::io::Error) -> Self { 30 - SitemapErr::IoErr(value) 31 - } 32 - } 33 - 34 - impl From<ignore::Error> for SitemapErr { 35 - fn from(value: ignore::Error) -> Self { 36 - SitemapErr::IgnoreErr(value) 37 - } 38 - } 39 - 40 - impl From<std::path::StripPrefixError> for SitemapErr { 41 - fn from(value: std::path::StripPrefixError) -> Self { 42 - SitemapErr::StripPrefixErr(value) 43 - } 44 - } 45 - 46 - impl Error for SitemapErr {} 47 - 48 - impl fmt::Display for SitemapErr { 49 - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 50 - match self { 51 - SitemapErr::IoErr(err) => write!(f, "IO Error: {}", err), 52 - SitemapErr::IgnoreErr(err) => write!(f, "Ignore Error: {}", err), 53 - SitemapErr::StripPrefixErr(err) => write!(f, "File Path Error: {}", err), 54 - SitemapErr::NotUTF8Path => write!(f, "Found a path that was not UTF-8"), 55 - } 56 - } 57 - } 58 - 59 34 pub fn local_sitemap( 60 35 dir: PathBuf, 61 36 include_dotfiles: bool, 62 37 use_gitignore: bool, 63 - ) -> Result<Sitemap, SitemapErr> { 38 + ) -> miette::Result<Sitemap, SitemapErr> { 64 39 let prefix = dir.canonicalize()?; 65 40 66 41 let mut res = HashMap::new();