1pub mod blame;
2pub mod cache;
3pub mod call_graph;
4pub mod can_gc;
5pub mod client;
6pub mod definition;
7pub mod field_layout;
8pub mod file_reader;
9pub mod nesting;
10pub mod search;
11pub mod types;
12pub mod utils;
13
14pub use blame::parse_commit_header;
15pub use client::SearchfoxClient;
16pub use search::{CategoryFilter, Lang, SearchOptions};
17pub use types::*;
18pub use utils::searchfox_url_repo;
19
20pub const VERSION: &str = env!("CARGO_PKG_VERSION");
21
22pub enum SearchfoxErrorKind {
23 Network,
24 Request,
25 Other,
26}
27
28pub fn classify_error(e: &anyhow::Error) -> SearchfoxErrorKind {
29 if let Some(re) = e.downcast_ref::<reqwest::Error>() {
30 if let Some(status) = re.status() {
31 if status.is_server_error() {
32 return SearchfoxErrorKind::Network;
33 }
34 if status.is_client_error() {
35 return SearchfoxErrorKind::Request;
36 }
37 }
38 return SearchfoxErrorKind::Network;
39 }
40
41 let msg = e.to_string();
42 if let Some(rest) = msg.strip_prefix("Request failed: ") {
43 if let Some(code_str) = rest.split_whitespace().next() {
44 if let Ok(code) = code_str.parse::<u16>() {
45 if code >= 500 {
46 return SearchfoxErrorKind::Network;
47 }
48 if code >= 400 {
49 return SearchfoxErrorKind::Request;
50 }
51 }
52 }
53 }
54
55 if msg.contains("Could not find file content") {
56 return SearchfoxErrorKind::Request;
57 }
58
59 SearchfoxErrorKind::Other
60}