Skip to content

Refactor decoding errors with more improvements #131

Description

@chshersh

Custom decoding errors were implemented in the following PR:

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:
  • 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
  • match table.get("asset_name").and_then(|t| t.as_table()) {
    None => AssetName {
    linux: None,
    macos: None,
    windows: None,
    },
  • 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.
  • fn str_by_key(table: &Map<String, Value>, key: &str) -> Option<String> {
    table.get(key).and_then(|v| v.as_str()).map(String::from)
    }
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

configTOML configuration, config-related CLI optionsgood first issueGood for newcomershacktoberfesthttps://hacktoberfest.com/

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions