rust-cli / rust-cli/config-rs

Panic when trying to deserialize a JSON map field while the actual config contains a non-map type

Open
#226 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

I have the following enum in my code:

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum my_enum {
    Foo { field: String },
    Bar { field: String }
}

And am trying to parse it in my configuration file, which had erroneous input:

...
 "my_field": "foo",
...

(instead of {"foo": {...}})

This caused the following panic:

thread 'main' panicked at 'internal error: entered unreachable code', /home/administrator/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/de.rs:335:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3c5e68de8aeb3970cd32ff45fd5d00ccc14da060/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/3c5e68de8aeb3970cd32ff45fd5d00ccc14da060/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/3c5e68de8aeb3970cd32ff45fd5d00ccc14da060/library/core/src/panicking.rs:50:5
   3: <config::de::EnumAccess as serde::de::VariantAccess>::struct_variant
   4: <config::de::MapAccess as serde::de::MapAccess>::next_value_seed
   5: venom::settings::opts::_::<impl serde::de::Deserialize for venom::settings::opts::InferenceSettings>::deserialize
   6: <config::de::MapAccess as serde::de::MapAccess>::next_value_seed
   7: venom::settings::opts::_::<impl serde::de::Deserialize for venom::settings::opts::GeneralSettings>::deserialize
   8: project::config::EnvironmentConfigBuilder::build
   9: venom::settings::opts::Settings::from_commandline_arguments
  10: venom::main

Probably a simple fix, just return an error in <config::de::EnumAccess as serde::de::VariantAccess>::struct_variant and its related functions instead of panicking.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in de.rs around the EnumAccess and VariantAccess implementation, especially struct_variant near line 335, and inspect the related functions for the same unreachable path. Reproduce deserialization with a string where a map-shaped enum value is expected; done means invalid input returns a deserialization error instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.