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::queue::SendQueue;
use crate::result::RudeResult;
use crate::try_log;
/// Root level of command.
///
@ -76,11 +77,13 @@ impl Parse for Command {
fn parse_subcommand(&self, s: String) -> RudeResult<(Self, String)> {
match self {
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))
}
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))
}
Self::Default => Err(ParserError::Default.into()),

@ -7,6 +7,7 @@ use crate::command::{CommandSetRoomDescription, Parse, ParserError};
use crate::database::Db;
use crate::queue::SendQueue;
use crate::result::RudeResult;
use crate::try_log;
/// Set room properties
#[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)> {
match self {
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))
}
Self::Default => Err(ParserError::Default.into()),

@ -7,6 +7,7 @@ use crate::command::{CommandSetPlayer, CommandSetRoom, CommandSetZone, Parse, Pa
use crate::database::Db;
use crate::queue::SendQueue;
use crate::result::RudeResult;
use crate::try_log;
/// Set various options
#[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)> {
match self {
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))
}
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))
}
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))
}
Self::Default => Err(ParserError::Default.into()),

@ -10,6 +10,7 @@ use mio::{Interest, Registry, Token};
use crate::client::Client;
use crate::result::*;
use crate::state::*;
use crate::try_log;
/// Connection information for the server.
#[derive(Debug)]
@ -44,7 +45,7 @@ impl Server {
/// Accept a new client connection
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 {
socket,

@ -7,6 +7,7 @@ use rusqlite::Row;
use serde_derive::{Deserialize, Serialize};
use crate::id::Id;
use crate::try_log;
use crate::world::{Area, AreaType};
/// 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> {
Ok(Self {
id: row.get("id")?,
parent: row.get("parent")?,
name: row.get("name")?,
users_visible: row.get("users_visible")?,
id: try_log!(row.get("id"), "Unable to get id from row"),
parent: try_log!(row.get("parent"), "Unable to get parent from row"),
name: try_log!(row.get("name"), "Unable to get name from row"),
users_visible: try_log!(
row.get("users_visible"),
"Unable to get users_visible from row"
),
areas: HashSet::new(),
})
}

Loading…
Cancel
Save