Repository: dbt-labs/dbt-core

Issue:
[CT-2956] [Regression] `dbt debug` returns success (0 exit code) when connection test fails
### Is this a regression in a recent version of dbt-core?

- [X] I believe this is a regression in dbt-core functionality
- [X] I have searched the existing issues, and I could not find an existing issue for this regression

I'm guessing that this is related to our changes to `dbt debug` in:
- https://github.com/dbt-labs/dbt-core/pull/7741

Reading through that PR, I don't believe this was one of the intended changes.

### Current Behavior

`dbt debug` is passing even if the connection test fails

### Expected/Previous Behavior

`dbt debug` should return a nonzero exit code if the connection test fails, and details on what failed

### Steps To Reproduce

Run `dbt debug` with a connection error

### Relevant log output

```shell
$ dbt debug
12:15:33  Running with dbt=1.5.4
12:15:33  dbt version: 1.5.4
12:15:33  python version: 3.10.11
12:15:33  python path: /Users/jerco/dev/product/dbt-core/env/bin/python3
12:15:33  os info: macOS-13.4.1-arm64-arm-64bit
12:15:33  Using profiles.yml file at /Users/jerco/.dbt/profiles.yml
12:15:33  Using dbt_project.yml file at /Users/jerco/dev/internal/internal-analytics/dbt_project.yml
12:15:33  Configuration:
12:15:34    profiles.yml file [OK found and valid]
12:15:34    dbt_project.yml file [OK found and valid]
12:15:34  Required dependencies:
12:15:34   - git [OK found]

12:15:34  Connection:
...
12:15:34  Registered adapter: snowflake=1.5.2
12:15:38    Connection test: [ERROR]

12:15:38  1 check failed:
12:15:38  dbt was unable to connect to the specified database.
The database returned the following error:

  >Database Error
  250001: Could not connect to Snowflake backend after 1 attempt(s).Aborting

Check your database credentials and try again. For more information, visit:
https://docs.getdbt.com/docs/configure-your-profile


$ echo $?
1

----

$ dbt debug
12:17:29  Running with dbt=1.6.0
12:17:29  dbt version: 1.6.0
12:17:29  python version: 3.10.11
12:17:29  python path: /Users/jerco/dev/product/dbt-core/env/bin/python3
12:17:29  os info: macOS-13.4.1-arm64-arm-64bit
12:17:30  Using profiles dir at /Users/jerco/.dbt
12:17:30  Using profiles.yml file at /Users/jerco/.dbt/profiles.yml
12:17:30  Using dbt_project.yml file at /Users/jerco/dev/internal/internal-analytics/dbt_project.yml
12:17:30  adapter type: snowflake
12:17:30  adapter version: 1.6.0
12:17:30  Configuration:
12:17:30    profiles.yml file [OK found and valid]
12:17:30    dbt_project.yml file [OK found and valid]
12:17:30  Required dependencies:
12:17:30   - git [OK found]

12:17:30  Connection:
...
12:17:30  Registered adapter: snowflake=1.6.0
12:17:33    Connection test: [ERROR]

12:17:33  All checks passed!
$ echo $?
0
```


### Environment

```markdown
- OS: macOS-13.4.1-arm64-arm-64bit
- Python: 3.10.11
- dbt (working version): 1.5.4
- dbt (regression version): 1.6.0
```


### Which database adapter are you using with dbt?

snowflake

### Additional Context

_No response_


Discussion:

Resolving patch:
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
@@ -149,13 +149,14 @@ def run(self) -> bool:
             dependencies_statuses = self.test_dependencies()
 
         # Test connection
-        self.test_connection()
+        connection_status = self.test_connection()
 
         # Log messages from any fails
         all_statuses: List[SubtaskStatus] = [
             load_profile_status,
             load_project_status,
             *dependencies_statuses,
+            connection_status,
         ]
         all_failing_statuses: List[SubtaskStatus] = list(
             filter(lambda status: status.run_status == RunStatus.Error, all_statuses)


Test patch: