Repository: dbt-labs/dbt-core

Issue:
dbt debug cannot handle an empty dbt_project.yml
### Describe the bug

If you call `dbt debug` on a new project that has an empty `dbt_project.yml` file, you get this error:

```
Encountered an error:
'NoneType' object does not support item assignment
```

### Steps To Reproduce

Create a new project directory and place an empty `dbt_project.yml` in it. Run `dbt debug`.

### Expected behavior

dbt should gracefully complain that I have an empty or malformed `dbt_project.yml`.

### Screenshots and log output

```
$ dbt debug
Running with dbt=0.15.2
dbt version: 0.15.2
python version: 3.7.6
python path: .../venv/bin/python
os info: Darwin-18.7.0-x86_64-i386-64bit
Using profiles.yml file at .../.dbt/profiles.yml

Encountered an error:
'NoneType' object does not support item assignment
```

### System information

**Which database are you using dbt with?**
- [x] postgres

**The output of `dbt --version`:**
```
$ dbt --version
installed version: 0.15.2
   latest version: 0.15.2

Up to date!
```

**The operating system you're using:** macOS

**The output of `python --version`:** Python 3.7.6



Discussion:
Thanks for the report @nchammas! Adding this to the current milestone. Would you be interested in contributing a fix for the issue? Happy to point you in the right direction if so!

Resolving patch:
diff --git a/core/dbt/config/project.py b/core/dbt/config/project.py
--- a/core/dbt/config/project.py
+++ b/core/dbt/config/project.py
@@ -188,6 +188,12 @@ def _raw_project_from(project_root: str) -> Dict[str, Any]:
         )
 
     project_dict = _load_yaml(project_yaml_filepath)
+
+    if not isinstance(project_dict, dict):
+        raise DbtProjectError(
+            'dbt_project.yml does not parse to a dictionary'
+        )
+
     return project_dict
 
 
diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py
--- a/core/dbt/task/debug.py
+++ b/core/dbt/task/debug.py
@@ -182,10 +182,10 @@ def _choose_profile_names(self) -> Optional[List[str]]:
         project_profile: Optional[str] = None
         if os.path.exists(self.project_path):
             try:
-                project_profile = load_yaml_text(
-                    dbt.clients.system.load_file_contents(self.project_path)
-                ).get('profile')
-            except dbt.exceptions.Exception:
+                project_profile = Project.partial_load(
+                    os.path.dirname(self.project_path)
+                ).profile_name
+            except dbt.exceptions.DbtProjectError:
                 pass
 
         args_profile: Optional[str] = getattr(self.args, 'profile', None)
@@ -196,19 +196,20 @@ def _choose_profile_names(self) -> Optional[List[str]]:
             pass
         # try to guess
 
+        profiles = []
         if self.raw_profile_data:
             profiles = [k for k in self.raw_profile_data if k != 'config']
-            if len(profiles) == 0:
+            if project_profile is None:
+                self.messages.append('Could not load dbt_project.yml')
+            elif len(profiles) == 0:
                 self.messages.append('The profiles.yml has no profiles')
             elif len(profiles) == 1:
                 self.messages.append(ONLY_PROFILE_MESSAGE.format(profiles[0]))
-                return profiles
             else:
                 self.messages.append(MULTIPLE_PROFILE_MESSAGE.format(
                     '\n'.join(' - {}'.format(o) for o in profiles)
                 ))
-                return profiles
-        return None
+        return profiles
 
     def _choose_target_name(self, profile_name: str):
         has_raw_profile = (


Test patch:
diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py
--- a/test/integration/049_dbt_debug_test/test_debug.py
+++ b/test/integration/049_dbt_debug_test/test_debug.py
@@ -91,6 +91,18 @@ def models(self):
     def capsys(self, capsys):
         self.capsys = capsys
 
+    @use_profile('postgres')
+    def test_postgres_empty_project(self):
+        with open('dbt_project.yml', 'w') as f:
+            pass
+        self.run_dbt(['debug', '--profile', 'test'])
+        splitout = self.capsys.readouterr().out.split('\n')
+        for line in splitout:
+            if line.strip().startswith('dbt_project.yml file'):
+                self.assertIn('ERROR invalid', line)
+            elif line.strip().startswith('profiles.yml file'):
+                self.assertNotIn('ERROR invalid', line)
+
     @use_profile('postgres')
     def test_postgres_badproject(self):
         # load a special project that is an error