Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing an ID is sometimes broken with a valid ID #11

Closed
jeromegn opened this issue Aug 24, 2023 · 3 comments
Closed

Parsing an ID is sometimes broken with a valid ID #11

jeromegn opened this issue Aug 24, 2023 · 3 comments

Comments

@jeromegn
Copy link

I have a valid uuid::UUID that can be converted to a valid uhlc::ID (I used try_into()), but I can't parse the timestamp once it has been serialized.

Test case:

#[cfg(test)]
mod tests {
    #[test]
    fn uhlc_ids() {
        let uuid: uuid::Uuid = "0478B15B80D54EE884B969D276E5B000".parse().unwrap();
        let clock = uhlc::HLCBuilder::new()
            .with_id(uuid.as_u128().try_into().unwrap())
            .build();

        let ts = clock.new_timestamp();

        println!("ts: {ts}");

        let ts: uhlc::Timestamp = ts.to_string().parse().unwrap();

        println!("parsed ts: {ts}");
    }
}

Produces:

ts: 2023-08-24T19:16:28.660307999Z/0b0e576d269b984e84ed5805bb17804
thread 'broadcast::tests::uhlc_ids' panicked at 'called `Result::unwrap()` on an `Err` value: ParseTimestampError { cause: "Leading 0s are not valid" }', crates/corro-types/src/broadcast.rs:367:58
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1687:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1089:23
   4: corro_types::broadcast::tests::uhlc_ids
             at ./src/broadcast.rs:367:35
   5: corro_types::broadcast::tests::uhlc_ids::{{closure}}
             at ./src/broadcast.rs:357:19
   6: core::ops::function::FnOnce::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test broadcast::tests::uhlc_ids ... FAILED

I believe this is because some valid IDs can start with zero?

@JEnoch
Copy link
Member

JEnoch commented Aug 25, 2023

Thanks for reporting this!
The problem lies between the internal representation of ID which is in little-endian, and its string parsing and display functions. #12 will fix this.

@JEnoch JEnoch closed this as completed in b1029d8 Aug 25, 2023
@jeromegn
Copy link
Author

Thanks! For now I had reverted to 0.5.x.

I'm not sure if there are benefits for me to switch to 0.6.x? The changelog only mentions UUID support deprecation. Is there anything else like bug fixes?

@JEnoch
Copy link
Member

JEnoch commented Aug 25, 2023

No, that's the only change between 0.5.2 and 0.6.0.

0.6.1 has just been released with this #12 fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants