Repository: omry/omegaconf

Issue:
Invalid error message assigning with an invalid inner Dict key.
```python
from dataclasses import dataclass, field
from typing import List, Any, Dict
from omegaconf import OmegaConf
from enum import Enum

class Color(Enum):
    RED = 1
    BLUE = 2
    GREEN = 3

@dataclass
class Dicts:
    d1: Dict[str, Any] = field(default_factory=lambda: {})
    d2: Dict[Color, str] = field(default_factory=lambda: {})

dicts = OmegaConf.structured(Dicts)
dicts.d2["10"] = "foo"
```
Error seems wrong
```
omegaconf.errors.KeyValidationError: Key '10' is incompatible with (Color) : Invalid value 'foo', expected one of:
	RED
	BLUE
	GREEN
	full_key: d2.10
	reference_type=Dict[Color, str]
	object_type=dict

```

Discussion:

Patch:
diff --git a/omegaconf/dictconfig.py b/omegaconf/dictconfig.py
index 640414a..5499a5b 100644
--- a/omegaconf/dictconfig.py
+++ b/omegaconf/dictconfig.py
@@ -257,9 +257,10 @@ class DictConfig(BaseContainer, MutableMapping[str, Any]):
                 ret = EnumNode.validate_and_convert_to_enum(key_type, key)
                 assert ret is not None
                 return ret
-            except ValidationError as e:
+            except ValidationError:
+                valid = ", ".join([x for x in key_type.__members__.keys()])
                 raise KeyValidationError(
-                    f"Key '$KEY' is incompatible with ({key_type.__name__}) : {e}"
+                    f"Key '$KEY' is incompatible with the enum type '{key_type.__name__}', valid: [{valid}]"
                 )
         else:
             assert False
diff --git a/omegaconf/nodes.py b/omegaconf/nodes.py
index dc19d95..21475da 100644
--- a/omegaconf/nodes.py
+++ b/omegaconf/nodes.py
@@ -379,9 +379,9 @@ class EnumNode(ValueNode):  # lgtm [py/missing-equals] : Intentional.
             assert False
 
         except (ValueError, KeyError) as e:
-            valid = "\n".join([f"\t{x}" for x in enum_type.__members__.keys()])
+            valid = ", ".join([x for x in enum_type.__members__.keys()])
             raise ValidationError(
-                f"Invalid value '$VALUE', expected one of:\n{valid}"
+                f"Invalid value '$VALUE', expected one of [{valid}]"
             ).with_traceback(sys.exc_info()[2]) from e
 
     def __deepcopy__(self, memo: Dict[int, Any] = {}) -> "EnumNode":


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
index 70193e9..e71496e 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -98,3 +98,9 @@ class MissingList:
 @dataclass
 class MissingDict:
     dict: Dict[str, str] = MISSING
+
+
+@dataclass
+class DictEnum:
+    color_key: Dict[Color, str] = field(default_factory=lambda: {})
+    color_val: Dict[str, Color] = field(default_factory=lambda: {})
diff --git a/tests/test_errors.py b/tests/test_errors.py
index 850638b..7227794 100644
--- a/tests/test_errors.py
+++ b/tests/test_errors.py
@@ -270,6 +270,28 @@ params = [
         ),
         id="dict,struct:setitem_on_none_existing_key",
     ),
+    pytest.param(
+        Expected(
+            create=lambda: DictConfig(key_type=Color, element_type=str, content={}),
+            op=lambda cfg: cfg.__setitem__("foo", "bar"),
+            exception_type=KeyValidationError,
+            msg="Key 'foo' is incompatible with the enum type 'Color', valid: [RED, GREEN, BLUE]",
+            full_key="foo",
+            key="foo",
+        ),
+        id="DictConfig[Color,str]:setitem_bad_key",
+    ),
+    pytest.param(
+        Expected(
+            create=lambda: DictConfig(key_type=str, element_type=Color, content={}),
+            op=lambda cfg: cfg.__setitem__("foo", "bar"),
+            exception_type=ValidationError,
+            msg="Invalid value 'bar', expected one of [RED, GREEN, BLUE]",
+            full_key="foo",
+            key="foo",
+        ),
+        id="DictConfig[str,Color]:setitem_bad_value",
+    ),
     # getitem
     pytest.param(
         Expected(
@@ -286,9 +308,9 @@ params = [
             create=lambda: DictConfig(key_type=Color, element_type=str, content={}),
             op=lambda cfg: cfg.__getitem__("foo"),
             exception_type=KeyValidationError,
-            msg="Key 'foo' is incompatible with (Color)",
+            msg="Key 'foo' is incompatible with the enum type 'Color', valid: [RED, GREEN, BLUE]",
             key="foo",
-            num_lines=7,
+            num_lines=4,
         ),
         id="DictConfig[Color,str]:getitem_str_key",
     ),