Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more error information from http admin API #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions senseicore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::{
io::ErrorKind,
};

use crate::services;

#[derive(Debug)]
pub enum Error {
Db(migration::DbErr),
Expand All @@ -30,12 +32,15 @@ pub enum Error {
FailedToWriteSeed,
SeedNotFound,
MacaroonNotFound,
Unauthenticated,
Unauthenticated(String),
InvalidMacaroon,
AdminNodeNotFound,
AdminNodeNotStarted,
AdminNodeNotCreated,
FundingGenerationNeverHappened,
NodeBeingStartedAlready,
AdminNodeService(services::admin::Error),
UnknownResponse,
}

impl Display for Error {
Expand All @@ -57,14 +62,17 @@ impl Display for Error {
Error::SeedNotFound => String::from("seed not found for node"),
Error::MacaroonNotFound => String::from("macaroon not found for node"),
Error::FailedToWriteSeed => String::from("failed to write seed"),
Error::Unauthenticated => String::from("unauthenticated"),
Error::Unauthenticated(msg) => format!("unauthenticated: {}", msg),
Error::InvalidMacaroon => String::from("invalid macaroon"),
Error::AdminNodeNotFound => String::from("admin node not found"),
Error::AdminNodeNotCreated => String::from("admin node not created"),
Error::AdminNodeNotStarted => String::from("admin node not started"),
Error::NodeBeingStartedAlready => String::from("node already being started"),
Error::FundingGenerationNeverHappened => {
String::from("funding generation for request never happened")
}
Error::AdminNodeService(e) => format!("admin node service error: {}", e),
Error::UnknownResponse => String::from("unknown response"),
};
write!(f, "{}", str)
}
Expand Down Expand Up @@ -142,6 +150,12 @@ impl From<macaroon::MacaroonError> for Error {
}
}

impl From<services::admin::Error> for Error {
fn from(e: services::admin::Error) -> Self {
Error::AdminNodeService(e)
}
}

impl From<Error> for std::io::Error {
fn from(e: Error) -> std::io::Error {
std::io::Error::new(ErrorKind::Other, e.to_string())
Expand Down
11 changes: 11 additions & 0 deletions senseicore/src/services/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use lightning_background_processor::BackgroundProcessor;
use macaroon::Macaroon;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet, VecDeque};
use std::fmt::{self, Display};
use std::sync::atomic::Ordering;
use std::{collections::hash_map::Entry, fs, sync::Arc};
use tokio::sync::{broadcast, Mutex};
Expand Down Expand Up @@ -216,6 +217,16 @@ pub enum Error {
Generic(String),
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// nEED TO DO THIS MATCH HERE???
let str = match self {
Error::Generic(e) => e.to_string(),
};
write!(f, "{}", str)
}
}

impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Generic(e.to_string())
Expand Down
Loading