pub enum Error {
Http(Error),
AnkiConnect(String),
EmptyResponse,
Json(Error),
ConnectionRefused,
PermissionDenied,
NoteValidation(String),
Config(String),
}Expand description
The error type for AnkiConnect operations.
§Common Patterns
§Checking if Anki is Running
use ankit::{AnkiClient, Error};
let client = AnkiClient::new();
// Try a simple operation to check connectivity
match client.misc().version().await {
Ok(version) => println!("Connected to AnkiConnect v{}", version),
Err(Error::ConnectionRefused) => {
return Err(Error::ConnectionRefused);
}
Err(e) => return Err(e),
}§Handling Duplicate Notes
use ankit::{AnkiClient, NoteBuilder, Error};
let client = AnkiClient::new();
let note = NoteBuilder::new("Default", "Basic")
.field("Front", "Hello")
.field("Back", "World")
.build();
match client.notes().add(note).await {
Ok(id) => println!("Created note {}", id),
Err(Error::AnkiConnect(msg)) if msg.contains("duplicate") => {
println!("Note already exists");
}
Err(e) => return Err(e),
}Variants§
Http(Error)
HTTP/network error from reqwest.
Typically indicates network issues unrelated to Anki.
For connection issues, see Error::ConnectionRefused.
AnkiConnect(String)
AnkiConnect returned an error message.
The message string contains details about what went wrong. Common messages include:
- “cannot create note because it is a duplicate”
- “deck was not found”
- “model was not found”
EmptyResponse
Response was empty (no result or error).
This is unexpected and may indicate an AnkiConnect bug.
Json(Error)
JSON serialization/deserialization error.
May occur if AnkiConnect returns unexpected data formats.
ConnectionRefused
Connection refused - Anki is likely not running.
This error occurs when:
- Anki is not running
- The AnkiConnect add-on is not installed
- AnkiConnect is configured on a different port
PermissionDenied
Permission denied by AnkiConnect.
This occurs when:
- An API key is required but not provided
- The provided API key is incorrect
- A request requires user approval in the Anki UI
NoteValidation(String)
Note validation failed.
The note could not be added due to validation issues (e.g., missing required fields).
Config(String)
Invalid configuration.
A configuration value was invalid or inconsistent.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.