replace ? with try_log! macro to log errors

master
rasul 5 years ago
parent c84f2e8c5b
commit 8fe7a14a75

@ -7,6 +7,7 @@ use crate::command::{CommandNew, CommandSet, Parse, ParserError};
use crate::database::Db; use crate::database::Db;
use crate::queue::SendQueue; use crate::queue::SendQueue;
use crate::result::RudeResult; use crate::result::RudeResult;
use crate::try_log;
/// Root level of command. /// Root level of command.
/// ///
@ -76,11 +77,13 @@ impl Parse for Command {
fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> { fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> {
match self { match self {
Self::New(_) => { Self::New(_) => {
let (command, args) = CommandNew::parse(s)?; let (command, args) =
try_log!(CommandNew::parse(s), "Unable to parse new subcommand");
Ok((Self::New(command), args)) Ok((Self::New(command), args))
} }
Self::Set(_) => { Self::Set(_) => {
let (command, args) = CommandSet::parse(s)?; let (command, args) =
try_log!(CommandSet::parse(s), "Unable to parse set subcommand");
Ok((Self::Set(command), args)) Ok((Self::Set(command), args))
} }
Self::Default => Err(ParserError::Default.into()), Self::Default => Err(ParserError::Default.into()),

@ -7,6 +7,7 @@ use crate::command::{CommandSetRoomDescription, Parse, ParserError};
use crate::database::Db; use crate::database::Db;
use crate::queue::SendQueue; use crate::queue::SendQueue;
use crate::result::RudeResult; use crate::result::RudeResult;
use crate::try_log;
/// Set room properties /// Set room properties
#[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)]
@ -42,7 +43,10 @@ impl Parse for CommandSetRoom {
fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> { fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> {
match self { match self {
Self::Description(_) => { Self::Description(_) => {
let (command, args) = CommandSetRoomDescription::parse(s)?; let (command, args) = try_log!(
CommandSetRoomDescription::parse(s),
"Unable to parse room description command"
);
Ok((Self::Description(command), args)) Ok((Self::Description(command), args))
} }
Self::Default => Err(ParserError::Default.into()), Self::Default => Err(ParserError::Default.into()),

@ -7,6 +7,7 @@ use crate::command::{CommandSetPlayer, CommandSetRoom, CommandSetZone, Parse, Pa
use crate::database::Db; use crate::database::Db;
use crate::queue::SendQueue; use crate::queue::SendQueue;
use crate::result::RudeResult; use crate::result::RudeResult;
use crate::try_log;
/// Set various options /// Set various options
#[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)]
@ -42,15 +43,20 @@ impl Parse for CommandSet {
fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> { fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> {
match self { match self {
Self::Player(_) => { Self::Player(_) => {
let (command, args) = CommandSetPlayer::parse(s)?; let (command, args) = try_log!(
CommandSetPlayer::parse(s),
"Unable to parse player subcommand",
);
Ok((Self::Player(command), args)) Ok((Self::Player(command), args))
} }
Self::Room(_) => { Self::Room(_) => {
let (command, args) = CommandSetRoom::parse(s)?; let (command, args) =
try_log!(CommandSetRoom::parse(s), "Unable to parse room subcommand",);
Ok((Self::Room(command), args)) Ok((Self::Room(command), args))
} }
Self::Zone(_) => { Self::Zone(_) => {
let (command, args) = CommandSetZone::parse(s)?; let (command, args) =
try_log!(CommandSetZone::parse(s), "Unable to parse zone subcommand",);
Ok((Self::Zone(command), args)) Ok((Self::Zone(command), args))
} }
Self::Default => Err(ParserError::Default.into()), Self::Default => Err(ParserError::Default.into()),

@ -10,6 +10,7 @@ use mio::{Interest, Registry, Token};
use crate::client::Client; use crate::client::Client;
use crate::result::*; use crate::result::*;
use crate::state::*; use crate::state::*;
use crate::try_log;
/// Connection information for the server. /// Connection information for the server.
#[derive(Debug)] #[derive(Debug)]
@ -44,7 +45,7 @@ impl Server {
/// Accept a new client connection /// Accept a new client connection
pub fn accept(&self, token: Token) -> RudeResult<Client> { pub fn accept(&self, token: Token) -> RudeResult<Client> {
let (socket, addr) = self.socket.accept()?; let (socket, addr) = try_log!(self.socket.accept(), "Unable to accept socket");
Ok(Client { Ok(Client {
socket, socket,

@ -7,6 +7,7 @@ use rusqlite::Row;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use crate::id::Id; use crate::id::Id;
use crate::try_log;
use crate::world::{Area, AreaType}; use crate::world::{Area, AreaType};
/// A collection of rooms and/or other zones. /// A collection of rooms and/or other zones.
@ -77,10 +78,13 @@ impl<'a> TryFrom<&Row<'a>> for Zone {
fn try_from(row: &Row) -> Result<Self, Self::Error> { fn try_from(row: &Row) -> Result<Self, Self::Error> {
Ok(Self { Ok(Self {
id: row.get("id")?, id: try_log!(row.get("id"), "Unable to get id from row"),
parent: row.get("parent")?, parent: try_log!(row.get("parent"), "Unable to get parent from row"),
name: row.get("name")?, name: try_log!(row.get("name"), "Unable to get name from row"),
users_visible: row.get("users_visible")?, users_visible: try_log!(
row.get("users_visible"),
"Unable to get users_visible from row"
),
areas: HashSet::new(), areas: HashSet::new(),
}) })
} }

Loading…
Cancel
Save