Repository: facebookresearch/hydra

Issue:
Better error message if config structure passed to instantiate is invalid.
# 🐛 Bug

In [common patterns#creating objects](https://cli.dev/docs/patterns/objects), if the `params` are mistakenly valued with a single string, the [`instantiate`](https://github.com/facebookresearch/hydra/blob/cb7904c666b34a53e09194993a0dd7b10fd97c99/hydra/utils.py#L44-L53) function exists with the error mentioned in "Stack trace/error messages":

This is fine to some extent, which is do you (Hydra team) aim at providing this kind of output messages? 

<!-- A clear and concise description of what the bug is. -->

## To reproduce

** Minimal Code/Config snippet to reproduce **

Set `params` to `bug_report` as in:

```YAML
class: ...
params: bug_report
```

** Stack trace/error message **
```
> AttributeError: 'str' object has no attribute 'merge_with'
[2019-10-16 02:25:21,592][hydra.utils][ERROR] - Error instantiating [[OBJECT_NAME]] : 'str' object has no attribute 'merge_with'
```
**Optional video**
If applicable, record a short [video](https://asciinema.org) with to help explain your problem.
You can also 

## Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->

I expect to have some sort of an error message explaining that `params` should be a collection of values where [[TYPE]] was provided. 
 
## System information
- <!-- Hydra Version --> Hydra Version: 0.9.0

- <!-- Operating system --> Operating System: Arch Linux

## Additional context
If you confirm that this should be fixed, I've already implemented the solution (IMO). 

Better error message if config structure passed to instantiate is invalid.
# 🐛 Bug

In [common patterns#creating objects](https://cli.dev/docs/patterns/objects), if the `params` are mistakenly valued with a single string, the [`instantiate`](https://github.com/facebookresearch/hydra/blob/cb7904c666b34a53e09194993a0dd7b10fd97c99/hydra/utils.py#L44-L53) function exists with the error mentioned in "Stack trace/error messages":

This is fine to some extent, which is do you (Hydra team) aim at providing this kind of output messages? 

<!-- A clear and concise description of what the bug is. -->

## To reproduce

** Minimal Code/Config snippet to reproduce **

Set `params` to `bug_report` as in:

```YAML
class: ...
params: bug_report
```

** Stack trace/error message **
```
> AttributeError: 'str' object has no attribute 'merge_with'
[2019-10-16 02:25:21,592][hydra.utils][ERROR] - Error instantiating [[OBJECT_NAME]] : 'str' object has no attribute 'merge_with'
```
**Optional video**
If applicable, record a short [video](https://asciinema.org) with to help explain your problem.
You can also 

## Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->

I expect to have some sort of an error message explaining that `params` should be a collection of values where [[TYPE]] was provided. 
 
## System information
- <!-- Hydra Version --> Hydra Version: 0.9.0

- <!-- Operating system --> Operating System: Arch Linux

## Additional context
If you confirm that this should be fixed, I've already implemented the solution (IMO). 



Discussion:

Resolving patch:
diff --git a/hydra/utils.py b/hydra/utils.py
--- a/hydra/utils.py
+++ b/hydra/utils.py
@@ -1,7 +1,7 @@
 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
 import logging.config
 
-from omegaconf import OmegaConf
+from omegaconf import OmegaConf, DictConfig
 
 # pylint: disable=C0103
 log = logging.getLogger(__name__)
@@ -46,6 +46,11 @@ def instantiate(config, *args, **kwargs):
     try:
         clazz = get_class(config["class"])
         params = config.params if "params" in config else OmegaConf.create()
+        assert isinstance(
+            params, DictConfig
+        ), "Input config params are expected to be a mapping, found {}".format(
+            type(config.params)
+        )
         params.merge_with(OmegaConf.create(kwargs))
         return clazz(*args, **params)
     except Exception as e:


Test patch: