Skip to content

Node::from_str() can panic #3153

@andrewdavidmackenzie

Description

@andrewdavidmackenzie

Describe the bug

  • I accept a NodeID (as String input in a text field) in a dialog in my app, to then connect to another node via iroh.
  • I create a NodeId from the string, checking for Ok/Err.
  • I have tests that check this works, and that invalid NodeIds are caught and the user informed
  • When updating from iroh-net to iroh, this test fails with a panic.

Relevant Logs

Expected behavior

  • NodeId::from_str() returns an error when an invalid string is passed in

Platform(s)
Desktop:

  • OS: macos
  • Version 15.3

Additional Context / Screenshots / GIFs
This code

impl FromStr for PublicKey {
    type Err = KeyParsingError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let bytes = decode_base32_hex(s)?;

        Ok(Self::from_bytes(&bytes)?)
    }
}

panics when you pass it a non-bas32 string (e.g. "invalid_node_id") and the parse error is not caught.

assert_eq!(Ok(output.len()), self.decode_len(input.len()));

in lib.rs:1453
I think that needs to be changed to return an Error, not panic.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions