Skip to main content

searchfox_lib/
lib.rs

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