searchfox_lib/
file_reader.rs1use crate::client::SearchfoxClient;
2use crate::utils::get_github_raw_url;
3use anyhow::Result;
4use log::error;
5
6impl SearchfoxClient {
7 pub async fn get_file(&self, path: &str) -> Result<String> {
8 let github_url = get_github_raw_url(&self.repo, path);
9
10 match self.get_raw(&github_url).await {
11 Ok(text) => Ok(text),
12 Err(e) => {
13 error!(
14 "GitHub fetch failed ({}). You can try viewing it at:\nhttps://searchfox.org/{}/source/{}",
15 e, self.repo, path
16 );
17 anyhow::bail!("Could not fetch file from GitHub");
18 }
19 }
20 }
21}