tool-sync icon indicating copy to clipboard operation
tool-sync copied to clipboard

Refactor decoding errors with more improvements

Open chshersh opened this issue 3 years ago • 3 comments

Custom decoding errors were implemented in the following PR:

  • #122

This issue is about some minor improvements to the implementation so they can be done separately:

  • [ ] Move Value::String("some value") into const EXPECTED_STRING or STRING_TYPE. It's a hack to reuse toml::Value for types of expected values. We can move them into top-level constants for easier reuse in the future:
  • https://github.com/chshersh/tool-sync/blob/f345444a548d215c2b560207b1ef031d18af28e2/src/config/toml.rs#L106
  • [ ] Return error when asset_name is not a table. Currently we return empty AssetName but we should provide a custom error when it's something like asset_name = "x86_64_unknown_linux_musl". Implement a similar constant to the previous task for string
  • https://github.com/chshersh/tool-sync/blob/f345444a548d215c2b560207b1ef031d18af28e2/src/config/toml.rs#L163-L168
  • [ ] Return error when str_by_key doesn't see String. The function returns Option<String>. Its type should be changed to Result<Option<String>, DecodeError> and its name should be changed to optional_str_by_key. And this function should throw an error when it sees something besides string.
  • https://github.com/chshersh/tool-sync/blob/f345444a548d215c2b560207b1ef031d18af28e2/src/config/toml.rs#L184-L186
  • [ ] Throw DecodeError when iterating through the map. We expect all tools to be tables. So we should iterate through the map, filter out expected keys (proxy and store_directory) and throw an error otherwise
  • https://github.com/chshersh/tool-sync/blob/f345444a548d215c2b560207b1ef031d18af28e2/src/config/toml.rs#L124-L126

chshersh avatar Oct 09 '22 11:10 chshersh

@DukeManh I created this issue as a follow-up to your improvements in #122. You don't need to implement this issue (unless you want to), someone else could contribute the improvements 🙂 You've created the mechanism but in this issue I propose to use it in even more places.

chshersh avatar Oct 09 '22 11:10 chshersh

Hi @chshersh I would like to work on this issue. Can you please assign it on my name?

ChellappanRajan avatar Oct 13 '22 18:10 ChellappanRajan

Hi @ChellappanRajan 👋🏻 Sure, go for it 👍🏻

chshersh avatar Oct 14 '22 07:10 chshersh