iggy icon indicating copy to clipboard operation
iggy copied to clipboard

When command is not handled sucessfully, print the command along with its arguments

Open hubcio opened this issue 1 year ago • 2 comments

Currently, if something goes wrong when command is handled, we have this print (this is example): 2024-01-22T10:04:18.487936Z ERROR server::binary::command: Command was not handled successfully, session: client ID: 4248576011, user ID: 1, IP address: 127.0.0.1:54398, error: Topic with name: test-topic for stream with ID: 1 already exists.

The aim of this task is to add command along with it's arguments to it. Preferably impl Display for Command and use it here, in the print, use anyhow with_context.

hubcio avatar Jan 22 '24 10:01 hubcio

Keep in mind that not all arguments should be displayed, for example user credentials during the authentication or message payload which might be sensitive.

spetz avatar Jan 22 '24 12:01 spetz

@spetz indeed.

IMHO below code should be modified to have sanitized args:

impl Display for Command {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Command::Ping(_) => write!(formatter, "{PING}"),
            Command::GetStats(_) => write!(formatter, "{GET_STATS}"),
            Command::GetMe(_) => write!(formatter, "{GET_ME}"),
            Command::GetClient(payload) => write!(formatter, "{GET_CLIENT}|{payload}"),
            Command::GetClients(_) => write!(formatter, "{GET_CLIENTS}"),
            Command::GetUser(payload) => write!(formatter, "{GET_USER}|{payload}"),
            Command::GetUsers(_) => write!(formatter, "{GET_USERS}"),
(..)
        }
    }

hubcio avatar Jan 23 '24 11:01 hubcio