matrix-org / rust-synapse-compress-state

A tool to compress some state in a Synapse instance's database
https://pypi.org/project/synapse-auto-compressor/
Apache License 2.0
142 stars 32 forks source link

Gracefully handle case where the given room ID on the CLI is not valid #59

Open TeknikalDomain opened 3 years ago

TeknikalDomain commented 3 years ago

Of all the things, I know this is probably... okay, nonexistent on the priority queue, but.

When an invalid / non-existent room ID is given to the -r option, the tool crashes:

# ./synapse_compress_state -p ... -r '!this_is:not.valid'
Fetching state from DB for room '!this_is:not.valid'...
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/database.rs:162:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I learned this when my monthly clean-up script was wrapping room IDs in double quotes, and everything was... unceremoniously failing. It seems like, as just a small user experience enhancement, it might be a good idea to catch this case and gracefully inform that Room '!this_is:not.valid' doesn't exist.