tauri_plugin_android_fs/
error.rs

1use serde::{ser::Serializer, Serialize};
2
3pub type Result<T> = std::result::Result<T, crate::Error>;
4
5/// Path error
6#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, thiserror::Error)]
7pub enum PathError {
8
9	/// When the path contains consecutive separators.
10    #[error("The path contains consecutive separators.")]
11    ConsecutiveSeparator,
12
13	/// When the path does not contain a filename.
14    #[error("The path does not contain a filename.")]
15    DoesNotContainFileName,
16
17	/// When the path does not contain a subdirectory.
18    #[error("The path does not contain a subdirectory.")]
19    DoesNotContainSubDir,
20
21	/// When the path is empty.
22	#[error("The path is empty.")]
23    Empty,
24}
25
26#[derive(Debug, thiserror::Error)]
27pub enum Error {
28
29	#[error("This device is not running Android. This plugin is only supported on Android.")]
30	NotAndroid,
31
32	#[error(transparent)]
33	Path(#[from] PathError),
34
35	#[error(transparent)]
36	Io(#[from] std::io::Error),
37  
38	#[error(transparent)]
39	PluginInvoke(#[from] anyhow::Error),
40}
41
42#[cfg(target_os = "android")]
43impl From<tauri::plugin::mobile::PluginInvokeError> for crate::Error {
44
45	fn from(value: tauri::plugin::mobile::PluginInvokeError) -> Self {
46		Self::PluginInvoke(anyhow::anyhow!("{value}"))
47	}
48}
49
50impl Serialize for crate::Error {
51
52	fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
53	where
54		S: Serializer,
55	{
56		serializer.serialize_str(self.to_string().as_ref())
57  	}
58}