Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better message when failing to match any variant of an untagged enum #773

Closed
dtolnay opened this issue Feb 18, 2017 · 5 comments
Closed

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 18, 2017

This message could be a lot better.

https://github.com/serde-rs/serde/blob/v0.9.7/serde_derive/src/de.rs#L750-L756

// TODO this message could be better by saving the errors from the failed
// attempts. The heuristic used by TOML was to count the number of fields
// processed before an error, and use the error that happened after the
// largest number of fields. I'm not sure I like that. Maybe it would be
// better to save all the errors and combine them into one message that
// explains why none of the variants matched.
let fallthrough_msg = format!("data did not match any variant of untagged enum {}", type_ident);
@dtolnay
Copy link
Member Author

dtolnay commented Feb 1, 2019

Closing as more complicated than it's worth. I would be willing to consider a PR that implements better error messages but I don't plan to pursue this as a priority.

@dtolnay dtolnay closed this as completed Feb 1, 2019
killercup pushed a commit to killercup/serde that referenced this issue Jun 1, 2019
This also adds a verbose-debug feature that enables the new behavior.

Previously:

> data did not match any variant of untagged enum ReferenceOr at line 6 column 4

Now, with `verbose-debug` feature enabled:

> data did not match any variant of untagged enum `ReferenceOr`
> 	- attempted to deserialize `Reference` but failed with: missing field `$ref`
> 	- attempted to deserialize `Item` but failed with: invalid value: string "lol", expected expected format `\dXX` at line 6 column 4

cf. serde-rs#773
@jschaf
Copy link

jschaf commented Apr 9, 2020

I don't have a PR but I'd like to add my experience with this error in case someone want to pick this up.

I've hit this error as a consumer (not developer) of the vector logging binary. The error is confusing because I'm not sure what went wrong. Specifically, here was the rough mental debugging I went through:

 ERROR vector: Configuration error: data did not match any variant of untagged enum 
    LuaConfig for key `transforms.journald_lua_transform`
  • Did I forget a field? Which one?
  • Is there an extra field? Which one?
  • Is the error referring to a key called data?
  • What is an untagged enum? Is it relevant to this error?

killercup pushed a commit to killercup/serde that referenced this issue Sep 25, 2020
This also adds a verbose-debug feature that enables the new behavior.

Previously:

> data did not match any variant of untagged enum ReferenceOr at line 6 column 4

Now, with `verbose-debug` feature enabled:

> data did not match any variant of untagged enum `ReferenceOr`
> 	- attempted to deserialize `Reference` but failed with: missing field `$ref`
> 	- attempted to deserialize `Item` but failed with: invalid value: string "lol", expected expected format `\dXX` at line 6 column 4

cf. serde-rs#773
cecton added a commit to paritytech/substrate that referenced this issue Nov 13, 2020
In polkadot:

---- call_function_actually_work stdout ----
thread 'call_function_actually_work' panicked at 'called `Result::unwrap()` on an `Err` value: RpcTransactionError { code: -32700, message: "Parse error", data: None }', node/test/service/tests/call-function.rs:29:60

Issues related:

serde-rs/json#559
serde-rs/serde#773
@abeluck
Copy link

abeluck commented Dec 11, 2020

I've hit this error as a consumer (not developer) of the vector logging binary. The error is confusing because I'm not sure what went wrong. Specifically, here was the rough mental debugging I went through:

 ERROR vector: Configuration error: data did not match any variant of untagged enum 
    LuaConfig for key `transforms.journald_lua_transform`

@jschaf sounds like i'm hitting the exact error you are (even down to transforms.journald_lua_transform). What was your eventual fix?

@jschaf
Copy link

jschaf commented Dec 11, 2020

@jschaf sounds like i'm hitting the exact error you are (even down to transforms.journald_lua_transform). What was your eventual fix?

Sorry, I've forgotten most of the context. It might have been mismatch between the docs which show version 2 rules, and the vector implementation at the time which defaulted to version 1. I remember diving through the vector source code to figure out what version 1 expected.

If it helps, here's my current working invocation of that transform:

# Transform to extract whitelisted fields from the JournalD src.
[transforms.journald_src]
  type = "lua"
  version = "2"
  inputs = ["journald_raw_src"]
  search_dirs = ["/etc/vector/lua"]
  source = "journald = require('journald')"
  hooks.process = 'journald.extract_whitelisted_fields'

@Peter-Sh
Copy link

@jschaf sounds like i'm hitting the exact error you are (even down to transforms.journald_lua_transform). What was your eventual fix?

To eventually save someone's time.
In my case the cause of error data did not match any variant of untagged enum LuaConfig was using type integer for version field instead of string.

type = "lua"
version = 2 # incorrect

Should be:

type = "lua"
version = "2"

emk added a commit to faradayio/openapi-interfaces that referenced this issue Sep 23, 2021
serde and serde_yaml generate terrible error messages for untagged
enums. We can fix this with manual deserialization.

Or at least improve it.

serde-rs/serde#773
serde-rs/serde#741
dtolnay/serde-yaml#201
@serde-rs serde-rs locked and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants