creddy/src-tauri/src/errors.rs

102 lines
3.0 KiB
Rust
Raw Normal View History

2022-08-14 13:27:41 -07:00
use std::fmt::{Display, Formatter};
use std::convert::From;
use std::str::Utf8Error;
2022-12-21 11:01:34 -08:00
use thiserror::Error;
use aws_sdk_sts::{
types::SdkError as AwsSdkError,
error::GetSessionTokenError,
};
2022-12-03 21:47:09 -08:00
use sqlx::{
error::Error as SqlxError,
migrate::MigrateError,
};
// error during initial setup (primarily loading state from db)
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-12-03 21:47:09 -08:00
pub enum SetupError {
2022-12-21 11:01:34 -08:00
#[error("Invalid database record")]
2022-12-03 21:47:09 -08:00
InvalidRecord, // e.g. wrong size blob for nonce or salt
2022-12-21 11:01:34 -08:00
#[error("Error from database: {0}")]
DbError(#[from] SqlxError),
#[error("Error running migrations: {0}")]
MigrationError(#[from] MigrateError)
2022-12-03 21:47:09 -08:00
}
2022-11-28 16:16:33 -08:00
2022-12-21 11:01:34 -08:00
// error when attempting to tell a request handler whether to release or deny credentials
#[derive(Debug, Error)]
2022-11-28 16:16:33 -08:00
pub enum SendResponseError {
2022-12-21 11:01:34 -08:00
#[error("The specified credentials request was not found")]
2022-11-28 16:16:33 -08:00
NotFound, // no request with the given id
2022-12-21 11:01:34 -08:00
#[error("The specified request was already closed by the client")]
2022-11-28 16:16:33 -08:00
Abandoned, // request has already been closed by client
}
2022-08-14 13:27:41 -07:00
2022-11-28 16:16:33 -08:00
// errors encountered while handling an HTTP request
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-08-14 13:27:41 -07:00
pub enum RequestError {
2022-12-21 11:01:34 -08:00
#[error("Error writing to stream: {0}")]
StreamIOError(#[from] std::io::Error),
#[error("Received invalid UTF-8 in request")]
2022-08-14 13:27:41 -07:00
InvalidUtf8,
2022-12-21 11:01:34 -08:00
// MalformedHttpRequest,
#[error("HTTP request too large")]
2022-08-14 13:27:41 -07:00
RequestTooLarge,
2022-12-21 11:01:34 -08:00
#[error("Error accessing credentials: {0}")]
NoCredentials(#[from] GetCredentialsError),
#[error("Error getting client details: {0}")]
ClientInfo(#[from] ClientInfoError),
#[error("Error from Tauri: {0}")]
Tauri(#[from] tauri::Error),
#[error("No main application window found")]
2022-12-19 15:26:44 -08:00
NoMainWindow,
2022-08-14 13:27:41 -07:00
}
2022-12-03 21:47:09 -08:00
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-12-03 21:47:09 -08:00
pub enum GetCredentialsError {
2022-12-21 11:01:34 -08:00
#[error("Credentials are currently locked")]
2022-12-03 21:47:09 -08:00
Locked,
2022-12-21 11:01:34 -08:00
#[error("No credentials are known")]
2022-12-03 21:47:09 -08:00
Empty,
}
2022-12-19 15:26:44 -08:00
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-12-19 15:26:44 -08:00
pub enum GetSessionError {
2022-12-21 11:01:34 -08:00
#[error("Request completed successfully but no credentials were returned")]
2022-12-19 15:26:44 -08:00
NoCredentials, // SDK returned successfully but credentials are None
2022-12-21 11:01:34 -08:00
#[error("Error response from AWS SDK: {0}")]
SdkError(#[from] AwsSdkError<GetSessionTokenError>),
2022-12-19 15:26:44 -08:00
}
2022-12-03 21:47:09 -08:00
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-12-03 21:47:09 -08:00
pub enum UnlockError {
2022-12-21 11:01:34 -08:00
#[error("App is not locked")]
2022-12-03 21:47:09 -08:00
NotLocked,
2022-12-21 11:01:34 -08:00
#[error("No saved credentials were found")]
2022-12-03 21:47:09 -08:00
NoCredentials,
2022-12-21 11:01:34 -08:00
#[error("Invalid passphrase")]
2022-12-03 21:47:09 -08:00
BadPassphrase,
2022-12-21 11:01:34 -08:00
#[error("Data was found to be corrupt after decryption")]
2022-12-03 21:47:09 -08:00
InvalidUtf8, // Somehow we got invalid utf-8 even though decryption succeeded
2022-12-21 11:01:34 -08:00
#[error("Database error: {0}")]
DbError(#[from] SqlxError),
#[error("Failed to create AWS session: {0}")]
GetSession(#[from] GetSessionError),
2022-12-03 21:47:09 -08:00
}
// Errors encountered while trying to figure out who's on the other end of a request
2022-12-21 11:01:34 -08:00
#[derive(Debug, Error)]
2022-12-03 21:47:09 -08:00
pub enum ClientInfoError {
2022-12-21 11:01:34 -08:00
#[error("Found PID for client socket, but no corresponding process")]
ProcessNotFound,
#[error("Couldn't get client socket details: {0}")]
NetstatError(#[from] netstat2::error::Error),
2022-12-03 21:47:09 -08:00
}