Repository: dbt-labs/dbt-core

Issue:
unhelpful error message when a profile is misconfigured
## Issue

### Issue description
If a misconfigured profile is provided (examples below) dbt can fail with an error like:
```
$ dbt compile
Encountered an error:
default
```

This failure occurs for any of `dbt compile`, `dbt seed`, `dbt run`, etc.

An example invalid profile looks like:

```yml
default:
  target: nonexistent_target
  outputs:
    dev:
      type: postgres
      host: localhost
      user: drew
      pass: password
      port: 5432
      dbname: analytics
      schema: demo_schema
      threads: 8
```

Here, a nonexistent `target` is specified on the second line. This error can additionally occur if a `target` config is missing altogether. 

### Results
Whereas this should show a helpful error, it instead shows a cryptic and confusing error like:
```
$ dbt compile
Encountered an error:
default
```

### System information
The output of `dbt --version`:
```
installed version: 0.10.2-a4
   latest version: 0.10.1

Your version of dbt is ahead of the latest release!
```

This behavior also occurs on 0.10.1.

The operating system you're running on:
macOS

The python version you're using (probably the output of `python --version`)
3.6.4

### Steps to reproduce
Create a profile like this:
```
badprofile:
  target: nonexistent_target
  outputs:
    dev:
      type: postgres
      host: localhost
      user: drew
      pass: password
      port: 5432
      dbname: analytics
      schema: demo_schema
      threads: 8
```

And a `dbt_project.yml` like this:
```
name: 'my_project'
version: '1.0'

source-paths: ["models", "tests"]   # paths with source code to compile
analysis-paths: ["analysis"] # path with analysis files which are compiled, but
                             # not run
target-path: "target"      # path for compiled code
clean-targets: ["target"]  # directories removed by the clean task
test-paths: ["test"]       # where to store test results
data-paths: ["data"]       # load CSVs from this directory with `dbt seed`
macro-paths: ["macros"]

profile: badprofile
```

and then run `dbt compile`
unhelpful error message when a profile is misconfigured
## Issue

### Issue description
If a misconfigured profile is provided (examples below) dbt can fail with an error like:
```
$ dbt compile
Encountered an error:
default
```

This failure occurs for any of `dbt compile`, `dbt seed`, `dbt run`, etc.

An example invalid profile looks like:

```yml
default:
  target: nonexistent_target
  outputs:
    dev:
      type: postgres
      host: localhost
      user: drew
      pass: password
      port: 5432
      dbname: analytics
      schema: demo_schema
      threads: 8
```

Here, a nonexistent `target` is specified on the second line. This error can additionally occur if a `target` config is missing altogether. 

### Results
Whereas this should show a helpful error, it instead shows a cryptic and confusing error like:
```
$ dbt compile
Encountered an error:
default
```

### System information
The output of `dbt --version`:
```
installed version: 0.10.2-a4
   latest version: 0.10.1

Your version of dbt is ahead of the latest release!
```

This behavior also occurs on 0.10.1.

The operating system you're running on:
macOS

The python version you're using (probably the output of `python --version`)
3.6.4

### Steps to reproduce
Create a profile like this:
```
badprofile:
  target: nonexistent_target
  outputs:
    dev:
      type: postgres
      host: localhost
      user: drew
      pass: password
      port: 5432
      dbname: analytics
      schema: demo_schema
      threads: 8
```

And a `dbt_project.yml` like this:
```
name: 'my_project'
version: '1.0'

source-paths: ["models", "tests"]   # paths with source code to compile
analysis-paths: ["analysis"] # path with analysis files which are compiled, but
                             # not run
target-path: "target"      # path for compiled code
clean-targets: ["target"]  # directories removed by the clean task
test-paths: ["test"]       # where to store test results
data-paths: ["data"]       # load CSVs from this directory with `dbt seed`
macro-paths: ["macros"]

profile: badprofile
```

and then run `dbt compile`


Discussion:

Resolving patch:
diff --git a/dbt/project.py b/dbt/project.py
--- a/dbt/project.py
+++ b/dbt/project.py
@@ -152,7 +152,8 @@ def compile_target(self, target_cfg):
 
     def compile_and_update_target(self):
         target = self.cfg['target']
-        self.cfg['outputs'][target].update(self.run_environment())
+        run_env = self.run_environment()
+        self.cfg['outputs'][target].update(run_env)
 
     def run_environment(self):
         target_name = self.cfg['target']
@@ -160,9 +161,17 @@ def run_environment(self):
             target_cfg = self.cfg['outputs'][target_name]
             return self.compile_target(target_cfg)
         else:
-            raise DbtProfileError(
-                    "'target' config was not found in profile entry for "
-                    "'{}'".format(target_name), self)
+
+            outputs = self.cfg.get('outputs', {}).keys()
+            output_names = [" - {}".format(output) for output in outputs]
+
+            msg = ("The profile '{}' does not have a target named '{}'. The "
+                   "valid target names for this profile are:\n{}".format(
+                        self.profile_to_load,
+                        target_name,
+                        "\n".join(output_names)))
+
+            raise DbtProfileError(msg, self)
 
     def get_target(self):
         ctx = self.context().get('env').copy()


Test patch: