diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/fatcat-cli/src/api.rs | 43 | ||||
-rw-r--r-- | rust/fatcat-cli/src/entities.rs | 3 | ||||
-rw-r--r-- | rust/fatcat-cli/src/lib.rs | 21 | ||||
-rw-r--r-- | rust/fatcat-cli/src/main.rs | 30 | ||||
-rw-r--r-- | rust/fatcat-cli/src/search.rs | 21 | ||||
-rw-r--r-- | rust/fatcat-cli/src/specifier.rs | 34 |
6 files changed, 65 insertions, 87 deletions
diff --git a/rust/fatcat-cli/src/api.rs b/rust/fatcat-cli/src/api.rs index e8b9e79..d26e6d5 100644 --- a/rust/fatcat-cli/src/api.rs +++ b/rust/fatcat-cli/src/api.rs @@ -1,8 +1,6 @@ -use log::{self,info,debug}; use hyper::client::ResponseFuture; -use fatcat_openapi; -use fatcat_openapi::{ApiNoContext, ApiError, ContextWrapperExt}; +use fatcat_openapi::{ApiNoContext, ContextWrapperExt}; use fatcat_openapi::client::Client; use fatcat_openapi::models; use swagger::{AuthData, ContextBuilder, EmptyContext, Push, XSpanIdString, auth}; @@ -10,9 +8,10 @@ use anyhow::{Result, anyhow, Context}; use crate::{ClientStatus,parse_macaroon_editor_id,Specifier, EntityType}; use tokio::runtime::current_thread::Runtime; +type FatcatApiContextType = swagger::make_context_ty!( ContextBuilder, EmptyContext, Option<AuthData>, XSpanIdString); pub struct FatcatApiClient<'a> { - pub api: fatcat_openapi::ContextWrapper<'a, Client<ResponseFuture>, swagger::make_context_ty!( ContextBuilder, EmptyContext, Option<AuthData>, XSpanIdString)>, + pub api: fatcat_openapi::ContextWrapper<'a, Client<ResponseFuture>, FatcatApiContextType>, pub rt: tokio::runtime::current_thread::Runtime, api_token: Option<String>, api_host: String, @@ -28,24 +27,14 @@ impl<'a> FatcatApiClient<'a> { None => None, }; //info!("{:?}", auth_data); - let context: swagger::make_context_ty!( - ContextBuilder, - EmptyContext, - Option<AuthData>, - XSpanIdString - ) = swagger::make_context!( + let context: FatcatApiContextType = swagger::make_context!( ContextBuilder, EmptyContext, auth_data, XSpanIdString::default() ); - let wrapped_client: fatcat_openapi::ContextWrapper<Client<ResponseFuture>, swagger::make_context_ty!( - ContextBuilder, - EmptyContext, - Option<AuthData>, - XSpanIdString - )> = client.with_context(context); + let wrapped_client: fatcat_openapi::ContextWrapper<Client<ResponseFuture>, FatcatApiContextType> = client.with_context(context); let rt: Runtime = Runtime::new().expect("create tokio runtime"); let editor_id = match api_token { @@ -56,7 +45,7 @@ impl<'a> FatcatApiClient<'a> { Ok(FatcatApiClient { api: wrapped_client, rt, - api_token: api_token, + api_token, editor_id, api_host, }) @@ -73,12 +62,12 @@ impl<'a> FatcatApiClient<'a> { fatcat_openapi::AuthCheckResponse::Success(_) => Ok(()), fatcat_openapi::AuthCheckResponse::Forbidden(err) => Err(anyhow!("Forbidden ({}): {}", err.error, err.message)), fatcat_openapi::AuthCheckResponse::NotAuthorized{body: err, ..} => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("auth check failed"))?, + resp => return Err(anyhow!("{:?}", resp)).context("auth check failed".to_string()), }.context("check auth token")?; match self.rt.block_on(self.api.get_editor(self.editor_id.as_ref().unwrap().to_string())).context("fetching editor account info")? { fatcat_openapi::GetEditorResponse::Found(editor) => Some(editor), - fatcat_openapi::GetEditorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message))?, - resp => Err(anyhow!("{:?}", resp)).context(format!("editor fetch failed"))?, + fatcat_openapi::GetEditorResponse::NotFound(err) => return Err(anyhow!("Not Found: {}", err.message)), + resp => return Err(anyhow!("{:?}", resp)).context("editor fetch failed".to_string()), } } else { None @@ -97,8 +86,8 @@ impl<'a> FatcatApiClient<'a> { ).context("fetch editgroups")?; let eg = match result { fatcat_openapi::GetEditgroupResponse::Found(eg) => eg, - other => Err(anyhow!("{:?}", other)) - .context(format!("failed to fetch editgroup {}", editgroup_id))?, + other => return Err(anyhow!("{:?}", other)) + .context(format!("failed to fetch editgroup {}", editgroup_id)), }; let result = self.rt.block_on( self.api.update_editgroup(editgroup_id.clone(), eg, Some(submit)) @@ -106,7 +95,7 @@ impl<'a> FatcatApiClient<'a> { match result { fatcat_openapi::UpdateEditgroupResponse::UpdatedEditgroup(eg) => Ok(eg), other => Err(anyhow!("{:?}", other)) - .context(format!("failed to submit editgroup {}", editgroup_id))?, + .context(format!("failed to submit editgroup {}", editgroup_id)), } } @@ -143,9 +132,9 @@ impl<'a> FatcatApiClient<'a> { other => Err(anyhow!("{:?}", other)), }, Editgroup(..) | Editor(..) => unimplemented!("deletion for this entity type"), - Changelog(..) => Err(anyhow!("mutating this entity type doesn't make sense"))?, + Changelog(..) => return Err(anyhow!("mutating this entity type doesn't make sense")), EditorUsername(..) | ReleaseLookup(..) | ContainerLookup(..) | FileLookup(..) | CreatorLookup(..) => - Err(anyhow!("into_entity_specifier() didn't work?"))?, + return Err(anyhow!("into_entity_specifier() didn't work?")), }.context(format!("failed to delete {:?}", specifier)) } @@ -229,9 +218,9 @@ impl<'a> FatcatApiClient<'a> { other => Err(anyhow!("{:?}", other)), }, Editgroup(..) | Editor(..) => unimplemented!("updates for this entity type"), - Changelog(..) => Err(anyhow!("deleting this entity type doesn't make sense"))?, + Changelog(..) => return Err(anyhow!("deleting this entity type doesn't make sense")), EditorUsername(..) | ReleaseLookup(..) | ContainerLookup(..) | FileLookup(..) | CreatorLookup(..) => - Err(anyhow!("into_entity_specifier() didn't work?"))?, + return Err(anyhow!("into_entity_specifier() didn't work?")), }.context(format!("failed to update {:?}", specifier)) } } diff --git a/rust/fatcat-cli/src/entities.rs b/rust/fatcat-cli/src/entities.rs index bc5c6f3..1b423d7 100644 --- a/rust/fatcat-cli/src/entities.rs +++ b/rust/fatcat-cli/src/entities.rs @@ -3,9 +3,6 @@ use std::str::FromStr; use anyhow::{Result, anyhow, Context}; use lazy_static::lazy_static; use regex::Regex; -use toml; -use serde_json; -use serde; use fatcat_openapi::models; use crate::Specifier; diff --git a/rust/fatcat-cli/src/lib.rs b/rust/fatcat-cli/src/lib.rs index defa18a..1fffd50 100644 --- a/rust/fatcat-cli/src/lib.rs +++ b/rust/fatcat-cli/src/lib.rs @@ -6,11 +6,9 @@ use tabwriter::TabWriter; use chrono_humanize::HumanTime; use anyhow::{Result, anyhow, Context}; use std::io::Write; -use atty; use termcolor::{ColorChoice, StandardStream, Color, ColorSpec, WriteColor}; use data_encoding::BASE64; use macaroon::{Macaroon, Verifier}; -use fatcat_openapi; use fatcat_openapi::models; #[allow(unused_imports)] use log::{self,info,debug}; @@ -79,15 +77,12 @@ impl ClientStatus { }; color_stdout.set_color(&color_normal)?; write!(&mut color_stdout, "{:>16}: ", "API auth token")?; - match self.has_api_token { - true => { - color_stdout.set_color(&color_happy)?; - writeln!(&mut color_stdout, "[configured]")?; - }, - false => { - color_stdout.set_color(&color_sad)?; - writeln!(&mut color_stdout, "[not configured]")?; - }, + if self.has_api_token { + color_stdout.set_color(&color_happy)?; + writeln!(&mut color_stdout, "[configured]")?; + } else { + color_stdout.set_color(&color_sad)?; + writeln!(&mut color_stdout, "[not configured]")?; }; if let Some(editor) = self.account { color_stdout.set_color(&color_normal)?; @@ -163,7 +158,7 @@ pub fn parse_macaroon_editor_id(s: &str) -> Result<String> { } let editor_id = match editor_id { Some(id) => id, - None => Err(anyhow!("expected an editor_id caveat in macaroon token"))?, + None => return Err(anyhow!("expected an editor_id caveat in macaroon token")), }; verifier.satisfy_exact(&format!("editor_id = {}", editor_id.to_string())); Ok(editor_id) @@ -183,7 +178,7 @@ pub fn print_editgroups(eg_list: Vec<models::Editgroup>, json: bool) -> Result<( eg.changelog_index.map_or("-".to_string(), |v| v.to_string()), eg.created.map_or("-".to_string(), |v| HumanTime::from(v).to_string()), eg.submitted.map_or("-".to_string(), |v| HumanTime::from(v).to_string()), - eg.description.unwrap_or("-".to_string()))?; + eg.description.unwrap_or_else(|| "-".to_string()))?; } tw.flush()?; } diff --git a/rust/fatcat-cli/src/main.rs b/rust/fatcat-cli/src/main.rs index 3ce46d1..ccd47d3 100644 --- a/rust/fatcat-cli/src/main.rs +++ b/rust/fatcat-cli/src/main.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use fatcat_cli::ApiModelSer; -use atty; use std::io::Write; use termcolor::{ColorChoice, StandardStream, Color, ColorSpec, WriteColor}; use anyhow::{Result, Context, anyhow}; @@ -168,14 +167,11 @@ fn main() -> Result<()> { if let Err(err) = run(opt) { // Be graceful about some errors if let Some(io_err) = err.root_cause().downcast_ref::<std::io::Error>() { - match io_err.kind() { - std::io::ErrorKind::BrokenPipe => { - // presumably due to something like writing to stdout and piped to `head -n10` and - // stdout was closed - debug!("got BrokenPipe error, assuming stdout closed as expected and exiting with success"); - std::process::exit(0); - }, - _ => (), + if let std::io::ErrorKind::BrokenPipe = io_err.kind() { + // presumably due to something like writing to stdout and piped to `head -n10` and + // stdout was closed + debug!("got BrokenPipe error, assuming stdout closed as expected and exiting with success"); + std::process::exit(0); } } let mut color_stderr = StandardStream::stderr( @@ -201,7 +197,7 @@ fn run(opt: Opt) -> Result<()> { // Using HTTP client::Client::try_new_http(&opt.api_host).context("Failed to create HTTP client")? } else { - Err(anyhow!("unsupported API Host prefix: {}", opt.api_host))? + return Err(anyhow!("unsupported API Host prefix: {}", opt.api_host)); }; let mut api_client = FatcatApiClient::new(&client, opt.api_host.clone(), opt.api_token.clone())?; @@ -256,7 +252,7 @@ fn run(opt: Opt) -> Result<()> { .expect("failed to execute process"); let cmd_status = editor_cmd.wait()?; if !cmd_status.success() { - Err(anyhow!("editor ({}) exited with non-success status code ({}), bailing on edit", editing_command, cmd_status.code().map(|v| v.to_string()).unwrap_or("N/A".to_string())))?; + return Err(anyhow!("editor ({}) exited with non-success status code ({}), bailing on edit", editing_command, cmd_status.code().map(|v| v.to_string()).unwrap_or_else(|| "N/A".to_string()))); }; let json_str = read_entity_file(Some(tmp_file.path().to_path_buf()))?; // for whatever reason api_client's TCP connection is broken after spawning, so try a @@ -288,13 +284,13 @@ fn run(opt: Opt) -> Result<()> { }, Command::Delete { specifier, editgroup_id } => { let result = api_client.delete_entity(specifier.clone(), editgroup_id) - .context(format!("delete entity: {:?}", specifier.clone()))?; + .context(format!("delete entity: {:?}", specifier))?; println!("{}", serde_json::to_string(&result)?); }, Command::Editgroup { cmd: EditgroupCommand::List { editor_id, limit, json } } => { let editor_id = match editor_id.or(api_client.editor_id) { Some(eid) => eid, - None => Err(anyhow!("require either working auth token or --editor-id"))?, + None => return Err(anyhow!("require either working auth token or --editor-id")), }; let result = api_client.rt.block_on( api_client.api.get_editor_editgroups(editor_id.clone(), Some(limit), None, None) @@ -303,7 +299,7 @@ fn run(opt: Opt) -> Result<()> { fatcat_openapi::GetEditorEditgroupsResponse::Found(eg_list) => { print_editgroups(eg_list, json)?; }, - other => Err(anyhow!("{:?}", other)).context(format!("failed to fetch editgroups for editor_{}", editor_id))?, + other => return Err(anyhow!("{:?}", other)).context(format!("failed to fetch editgroups for editor_{}", editor_id)), } }, Command::Editgroup { cmd: EditgroupCommand::Reviewable { limit, json } } => { @@ -314,7 +310,7 @@ fn run(opt: Opt) -> Result<()> { fatcat_openapi::GetEditgroupsReviewableResponse::Found(eg_list) => { print_editgroups(eg_list, json)?; }, - other => Err(anyhow!("{:?}", other)).context(format!("failed to fetch reviewable editgroups"))?, + other => return Err(anyhow!("{:?}", other)).context("failed to fetch reviewable editgroups".to_string()), } }, Command::Editgroup { cmd: EditgroupCommand::Create { description }} => { @@ -330,7 +326,7 @@ fn run(opt: Opt) -> Result<()> { match result { fatcat_openapi::CreateEditgroupResponse::SuccessfullyCreated(eg) => println!("{}", serde_json::to_string(&eg)?), - other => Err(anyhow!("{:?}", other)).context(format!("failed to create editgroup"))?, + other => return Err(anyhow!("{:?}", other)).context("failed to create editgroup".to_string()), } }, Command::Editgroup { cmd: EditgroupCommand::Accept { editgroup_id } } => { @@ -340,7 +336,7 @@ fn run(opt: Opt) -> Result<()> { match result { fatcat_openapi::AcceptEditgroupResponse::MergedSuccessfully(msg) => println!("{}", serde_json::to_string(&msg)?), - other => Err(anyhow!("failed to accept editgroup {}: {:?}", editgroup_id, other))?, + other => return Err(anyhow!("failed to accept editgroup {}: {:?}", editgroup_id, other)), } }, Command::Editgroup { cmd: EditgroupCommand::Submit{ editgroup_id } } => { diff --git a/rust/fatcat-cli/src/search.rs b/rust/fatcat-cli/src/search.rs index ec5d1d6..4e3fcbd 100644 --- a/rust/fatcat-cli/src/search.rs +++ b/rust/fatcat-cli/src/search.rs @@ -29,7 +29,7 @@ impl Iterator for SearchResults { } } // if current batch is empty, and we are scrolling, refill the current batch - if self.batch.len() == 0 && self.scroll_id.is_some() { + if self.batch.is_empty() && self.scroll_id.is_some() { let response = self.http_client.get(&self.scroll_url) .header("Content-Type", "application/json") .body(json!({ @@ -53,16 +53,16 @@ impl Iterator for SearchResults { } // return next hit from the most recent batch - if self.batch.len() > 0 { + if !self.batch.is_empty() { self.offset += 1; let val = self.batch.pop().unwrap(); let source = val["_source"].clone(); - return Some(Ok(source)) + return Some(Ok(source)); } // if batch is empty and couldn't be refilled, terminate // TODO: should we raise error if ended early? - return None + None } } @@ -72,7 +72,7 @@ pub fn crude_search(api_host: &str, entity_type: EntityType, limit: Option<u64>, EntityType::Release => "fatcat_release", EntityType::File => "fatcat_file", EntityType::Container => "fatcat_container", - _ => Err(anyhow!("No search index for entity type: {:?}", entity_type))?, + _ => return Err(anyhow!("No search index for entity type: {:?}", entity_type)), }; let http_client = reqwest::Client::builder() .timeout(Duration::from_secs(10)) @@ -80,7 +80,7 @@ pub fn crude_search(api_host: &str, entity_type: EntityType, limit: Option<u64>, .build() .expect("ERROR :: Could not build reqwest client"); - let query: String = if terms.len() == 0 { + let query: String = if terms.is_empty() { "*".to_string() } else { terms.join(" ") @@ -148,14 +148,15 @@ pub fn crude_search(api_host: &str, entity_type: EntityType, limit: Option<u64>, let mut response = request.send()?; if !response.status().is_success() { - Err(anyhow!("search error, status={}", response.status()))?; + return Err(anyhow!("search error, status={}", response.status())); } //println!("{:?}", response); let body: serde_json::Value = response.json()?; - let scroll_id = match scroll_mode { - false => None, - true => Some(body["_scroll_id"].as_str().unwrap().to_string()), + let scroll_id = if scroll_mode { + None + } else { + Some(body["_scroll_id"].as_str().unwrap().to_string()) }; Ok(SearchResults { diff --git a/rust/fatcat-cli/src/specifier.rs b/rust/fatcat-cli/src/specifier.rs index f8b4420..0cb5014 100644 --- a/rust/fatcat-cli/src/specifier.rs +++ b/rust/fatcat-cli/src/specifier.rs @@ -78,7 +78,7 @@ impl Specifier { fatcat_openapi::GetReleaseResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetReleaseResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetReleaseResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, ReleaseLookup(ext_id, key) => { use ReleaseLookupKey::*; @@ -95,7 +95,7 @@ impl Specifier { fatcat_openapi::LookupReleaseResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::LookupReleaseResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::LookupReleaseResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), } }, Work(fcid) => @@ -103,14 +103,14 @@ impl Specifier { fatcat_openapi::GetWorkResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetWorkResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetWorkResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, Container(fcid) => match api_client.rt.block_on(api_client.api.get_container(fcid.to_string(), None, None))? { fatcat_openapi::GetContainerResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetContainerResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetContainerResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, ContainerLookup(ext_id, key) => { let result = api_client.rt.block_on(match ext_id { @@ -120,7 +120,7 @@ impl Specifier { fatcat_openapi::LookupContainerResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::LookupContainerResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::LookupContainerResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), } }, Creator(fcid) => @@ -128,7 +128,7 @@ impl Specifier { fatcat_openapi::GetCreatorResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetCreatorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetCreatorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, CreatorLookup(ext_id, key) => { let result = api_client.rt.block_on(match ext_id { @@ -138,7 +138,7 @@ impl Specifier { fatcat_openapi::LookupCreatorResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::LookupCreatorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::LookupCreatorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), } }, File(fcid) => @@ -146,7 +146,7 @@ impl Specifier { fatcat_openapi::GetFileResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetFileResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetFileResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, FileLookup(hash, key) => { use FileLookupKey::*; @@ -162,7 +162,7 @@ impl Specifier { fatcat_openapi::LookupFileResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::LookupFileResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::LookupFileResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), } }, FileSet(fcid) => @@ -170,35 +170,35 @@ impl Specifier { fatcat_openapi::GetFilesetResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetFilesetResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetFilesetResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, WebCapture(fcid) => match api_client.rt.block_on(api_client.api.get_webcapture(fcid.to_string(), None, None))? { fatcat_openapi::GetWebcaptureResponse::FoundEntity(model) => Ok(Box::new(model)), fatcat_openapi::GetWebcaptureResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetWebcaptureResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, Editgroup(fcid) => match api_client.rt.block_on(api_client.api.get_editgroup(fcid.to_string()))? { fatcat_openapi::GetEditgroupResponse::Found(model) => Ok(Box::new(model)), fatcat_openapi::GetEditgroupResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetEditgroupResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, Editor(fcid) => match api_client.rt.block_on(api_client.api.get_editor(fcid.to_string()))? { fatcat_openapi::GetEditorResponse::Found(model) => Ok(Box::new(model)), fatcat_openapi::GetEditorResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetEditorResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, Changelog(index) => match api_client.rt.block_on(api_client.api.get_changelog_entry(*index))? { fatcat_openapi::GetChangelogEntryResponse::FoundChangelogEntry(model) => Ok(Box::new(model)), fatcat_openapi::GetChangelogEntryResponse::BadRequest(err) => Err(anyhow!("Bad Request ({}): {}", err.error, err.message)), fatcat_openapi::GetChangelogEntryResponse::NotFound(err) => Err(anyhow!("Not Found: {}", err.message)), - resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self))?, + resp => Err(anyhow!("{:?}", resp)).context(format!("API GET failed: {:?}", self)), }, EditorUsername(_username) => { unimplemented!("editor lookup by username isn't implemented in fatcat-server API yet, sorry") @@ -230,7 +230,7 @@ impl FromStr for Specifier { ("webcapture", fcid) => Ok(Specifier::WebCapture(fcid.to_string())), ("editgroup", fcid) => Ok(Specifier::Editgroup(fcid.to_string())), ("editor", fcid) => Ok(Specifier::Editor(fcid.to_string())), - _ => Err(anyhow!("unexpected fatcat FCID type: {}", &caps[1]))?, + _ => Err(anyhow!("unexpected fatcat FCID type: {}", &caps[1])), }; } @@ -250,7 +250,7 @@ impl FromStr for Specifier { ("sha256", key) => Ok(Specifier::FileLookup(FileLookupKey::SHA256, key.to_string())), ("md5", key) => Ok(Specifier::FileLookup(FileLookupKey::MD5, key.to_string())), ("username", key) => Ok(Specifier::EditorUsername(key.to_string())), - _ => Err(anyhow!("unexpected entity lookup type: {}", &caps[1]))?, + _ => Err(anyhow!("unexpected entity lookup type: {}", &caps[1])), }; } // lastly, changelog entity lookup @@ -260,7 +260,7 @@ impl FromStr for Specifier { if let Some(caps) = SPEC_CHANGELOG_RE.captures(s) { return Ok(Specifier::Changelog(caps[1].parse::<i64>()?)); } - return Err(anyhow!("expecting a specifier: entity identifier or key/value lookup: {}", s)) + Err(anyhow!("expecting a specifier: entity identifier or key/value lookup: {}", s)) } } |