Error while passing tests for bencoded Integer, in the bittorrent challenge

fn decode_bencoded_value(encoded_value: &str) -> serde_json::Value {
    let encoded_value = encoded_value.trim();
    // If encoded_value starts with a digit, it's a number
    if encoded_value.chars().next().unwrap().is_digit(10) {
        // Example: "5:hello" -> "hello"
        let colon_index = encoded_value.find(':').unwrap();
        let number_string = &encoded_value[..colon_index];
        let number = number_string.parse::<usize>().unwrap();
        let string = &encoded_value[colon_index + 1..colon_index + 1 + number];
        return serde_json::Value::String(string.to_string());
    } else if encoded_value.starts_with("i") && encoded_value.ends_with("e") {
        let extracted_integer = &encoded_value[1..encoded_value.len() - 1];
        let parsed_int = extracted_integer
            .parse::<i64>()
            .expect("Failed to parse int");
        return serde_json::Value::Number(serde_json::Number::from(parsed_int));
    } else {
        panic!("Unhandled encoded value: {}", encoded_value)
    }
}

This code works locally with any bencoded integer, but on the codecrafter runners it gives me error, here is a screenshot below

This has been solved, the issue was with git, a simple git commit -am instead of git commit -m did the job, I am not sure what was going wrong because i did do git add . but anyways it works now

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.