Skip to content

Commit

Permalink
Change some errors to anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
iduartgomez committed Jun 9, 2024
1 parent d243fdc commit 3cf8865
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
18 changes: 10 additions & 8 deletions crates/core/src/bin/freenet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ use freenet::{
};
use std::{net::SocketAddr, sync::Arc};

type DynError = Box<dyn std::error::Error + Send + Sync + 'static>;

async fn run(config: Config) -> Result<(), DynError> {
async fn run(config: Config) -> Result<(), anyhow::Error> {
match config.mode {
OperationMode::Local => run_local(config).await,
OperationMode::Network => run_network(config).await,
}
}

async fn run_local(config: Config) -> Result<(), DynError> {
async fn run_local(config: Config) -> Result<(), anyhow::Error> {
tracing::info!("Starting freenet node in local mode");
let port = config.ws_api.port;
let ip = config.ws_api.address;
let executor = Executor::from_config(Arc::new(config), None).await?;
let executor = Executor::from_config(Arc::new(config), None)
.await
.map_err(anyhow::Error::msg)?;

let socket: SocketAddr = (ip, port).into();
run_local_node(executor, socket).await
run_local_node(executor, socket)
.await
.map_err(anyhow::Error::msg)
}

async fn run_network(config: Config) -> Result<(), DynError> {
async fn run_network(config: Config) -> Result<(), anyhow::Error> {
tracing::info!("Starting freenet node in network mode");
run_network_node(config).await
}

fn main() -> Result<(), DynError> {
fn main() -> Result<(), anyhow::Error> {
freenet::config::set_logger(None);
let config = ConfigArgs::parse().build()?;
let rt = tokio::runtime::Builder::new_multi_thread()
Expand Down
11 changes: 6 additions & 5 deletions crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ impl ConfigArgs {
}
let filename = e.file_name().to_string_lossy().into_owned();
let ext = filename.rsplit('.').next().map(|s| s.to_owned());
tracing::info!("Found configuration file: {filename}, {ext:?}");
if let Some(ext) = ext {
if filename.starts_with("config") {
match ext.as_str() {
"toml" => {
tracing::info!("Found configuration file: {filename}.{ext}");
return Some((filename, ext));
}
"json" => {
Expand Down Expand Up @@ -202,12 +202,13 @@ impl ConfigArgs {
if self.config_paths.data_dir.is_none() {
self.config_paths.data_dir = Some(data);
}
Self::read_config(&config)?
Self::read_config(&config)?.map(|cfg| {
tracing::info!("Found configuration file in default directory");
cfg
})
};

if cfg.is_some() {
tracing::debug!("Found configuration file in default directory");
}
if cfg.is_some() {}

let should_persist = cfg.is_none();

Expand Down
3 changes: 1 addition & 2 deletions crates/core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use crate::{
ring::{Location, PeerKeyLocation},
router::{RouteEvent, RouteOutcome},
tracing::{EventRegister, NetEventLog, NetEventRegister},
DynError,
};
use crate::{
config::Config,
Expand All @@ -66,7 +65,7 @@ pub(crate) mod testing_impl;
pub struct Node(NodeP2P);

impl Node {
pub async fn run(self) -> Result<(), DynError> {
pub async fn run(self) -> Result<(), anyhow::Error> {
self.0.run_node().await?;
Ok(())
}
Expand Down
6 changes: 2 additions & 4 deletions crates/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,11 @@ pub mod local_node {
pub mod network_node {
use tower_http::trace::TraceLayer;

use crate::{
client_events::websocket::WebSocketProxy, config::Config, dev_tool::NodeConfig, DynError,
};
use crate::{client_events::websocket::WebSocketProxy, config::Config, dev_tool::NodeConfig};

use super::{http_gateway::HttpGateway, serve};

pub async fn run_network_node(config: Config) -> Result<(), DynError> {
pub async fn run_network_node(config: Config) -> Result<(), anyhow::Error> {
let ws_socket = (config.ws_api.address, config.ws_api.port).into();
let (gw, gw_router) = HttpGateway::as_router(&ws_socket);
let (ws_proxy, ws_router) = WebSocketProxy::as_router(gw_router);
Expand Down

0 comments on commit 3cf8865

Please sign in to comment.