Staging instance, all changes can be removed at any time

Skip to content

Improve ergonomics of error handling in properties accessors

vlorentz requested to merge properties-ergonomics into master

Property accessors returned None when the node_id (or filename_id) passed as argument is larger than the number of nodes (or label names), so every access to properties needs to unwrap it.

This is very redundant and not very helpful because it is unlikely to happen (users of swh-graph don't normally mint this themselves) and indicates either a bug in the user code or corrupted swh-graph files. Either way, panicking immediately is often the desired behavior.

Therefore, accessors now panic themselves when this happens, saving users of swh-graph the trouble. Users who want to check there is no error can use the try_ variants (which now return a Result instead of None).

However, some accessors still return Option, but now their None variant only indicates the value is absent, rather than an error (errors are either a panic in the default accessors, or an Err in the `try_ variants).

However, node_id and node_id_from_string_swhid keep their existing behavior, as they usually deal with external input, so it is best to avoid implicit panics when these are malformed.

Merge request reports

Loading