#wild rust behavior (skipping statements)

12 messages · Page 1 of 1 (latest)

tribal solstice
#

when logging with a new user, the second match clause Err(AppError::UserNotFound) should hit
but the first match clause is hitting (which is wild)
I checked my database (mongodb) over and over again there is no such entry of the email that I was using
and after hitting the first clause it is neither printing the User (u variable) and the cookies variable
it is a very odd behavior that rust skip statements like that, I have never seen that before
then it is hitting this statement ActiveSession::parse_and_verify(&cookies)

    pub fn parse_and_verify(cookies_list: &Vec<String>) -> Result<Self, AppError> {
        if cookies_list.is_empty() {
            return Err(AppError::Unauthorized("No cookie header found"));
        }
        let mut parsed_active_session = None;
        for cookies in cookies_list {
            if let Some(s) = cookies.split(';').find(|s| s.trim().starts_with("SSID=")) {
                parsed_active_session = Some(Self {
                    ssid: s.trim()[5..].to_string(),
                    decrypted_ssid: "".to_string(),
                });
                break;
            }
        }
        if let Some(mut active_session) = parsed_active_session {
            if let Some(s) = super::verify(&active_session.ssid) {
                active_session.decrypted_ssid = s;
                Ok(active_session)
            } else {
                Err(AppError::InvalidSession(active_session.expire()))
            }
        } else {
            Err(AppError::Unauthorized("Invalid Session"))
        }
    }

and directly returning this error Err(AppError::Unauthorized("No cookie header found"))
hitting that match clause should return a Redirect response from the inner match statement
the callback route is of around ~150 lines, is that the problem?

tribal solstice
#

wild rust behavior (skipping statements)

warped basin
#

so the Err(AppError::UserNotFound) branch needs to be above it

tribal solstice
warped basin
#

oops, thought the Err(_) branch you have for parse_and_verify was being used for the get_user_by_email match branch

#

regarding tracing not outputting messages, is your subscriber setup to buffer messages by any chance?

tribal solstice
#
    tracing_subscriber::registry()
        .with(tracing::level_filters::LevelFilter::from_level(
            tracing::Level::TRACE,
        ))
        .with(tracing_subscriber::fmt::Layer::default())
        .init();

this is what I have for tracing subscriber
but even dbg!() macro is not printing anything there

#

rust is blatantly skipping statements

tribal solstice
warped basin
#

i wonder what happens if you add a std::io::stdout().flush()?; statement after one of the tracing::error! statements

#

basically i think rust is actually writing the message but stdout is buffering it