Repository: dbt-labs/dbt-core

Issue:
[CT-2632] [Regression] --config-dir with dbt debug is thowing a cannot parse error
### Is this a new bug in dbt-core?

- [X] I believe this is a new bug in dbt-core
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

<img width="1328" alt="image" src="https://github.com/dbt-labs/dbt-core/assets/67295367/b54d7f24-ea47-4c9a-a7e0-ed8f6ca9447f">

Looks like the `--config-dir` flag is broken! Bug arises likely in [this structured logging related PR](https://github.com/dbt-labs/dbt-core/pull/4183) 

So this has been broken since `November 2021` or thereabouts.

The fix is to add a `str()` call on line ~108.

### Expected Behavior

Going back to [this positively ancient 6 year old issue](https://github.com/dbt-labs/dbt-core/pull/439/files), it seems like the original purpose is "if specified, dbt will show path information for this project."

Thankfully the current flag description is sort of consistent with this: `Show the configured location for the profiles.yml file and exit`. Really though, it just renders `open <what dbt thinks the profiles dir is>` which you manually copy-paste to the CLI. 

**Instead of fixing this, because it's causing confusion on our own team, I'm proposing, we just remove this.**

### Steps To Reproduce

1. kick a `dbt debug --config-dir`

### Relevant log output

```shell
see screenshot above
```


### Environment

```markdown
- OS: MacOS 13.3.1
- Python: 3.9.9
- dbt: dev
```


### Which database adapter are you using with dbt?

_No response_

### Additional Context

_No response_


Discussion:
I was able to reproduce this report, and I can confirm this command worked in dbt 1.4, but no longer works in dbt 1.5.

This was probably an unanticipated consequence of our migration to a `click`-based CLI since it sounds like this flag might be untested.

It sounds like the suspected fix would be here:
https://github.com/dbt-labs/dbt-core/blob/d0b5d752df177f58f91fc081ca29f05732c0d1b0/core/dbt/task/debug.py#L108

I didn't test it personally, but maybe something like:
```python
        fire_event(DebugCmdOut(msg="Using profiles.yml file at {}".format(str(self.profile_path))))
```

As an alternative to fixing this regression, there's a discussion in https://github.com/dbt-labs/dbt-core/pull/7793 about removing this flag altogether.
@dbeatty10 @VersusFacit It's worth noting that @tlento of the MetricFlow team encountered this same issue independently trying to get the profile directory from dbt, so this is definitely information people want. I'd suggest we fix this.

We should also consider a more general dbt command or mechanism. Perhaps a command which prints out the value of all the flags and terminates, or prints the value of a specified flag and terminates? I'd also suggest we return a dictionary of the calculated flag values with every invocation of dbtRunner, which would be helpful both for testing and general use.
That's great to know....it seems there's a use-case but the name is so strange/imprecise. Do we want to rename it? Do we feel comfortable simply having the profile dir get output with `dbt debug` by default as I suggest?

In other words, Is this a workflow we want to keep or would we rather fold it into the generic `debug`?
It seems there's enough ask to keep this in. So, that's fine! I'll close this and make #7793 work, while also adding the profile dir to the `debug` output, since there is no reason it shouldn't be a part of the info (also people wanted that added along with adapter version, and so on)

Resolving patch:
diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py
--- a/core/dbt/cli/params.py
+++ b/core/dbt/cli/params.py
@@ -43,7 +43,7 @@
 config_dir = click.option(
     "--config-dir",
     envvar=None,
-    help="Show the configured location for the profiles.yml file and exit",
+    help="Print a system-specific command to access the directory that the current dbt project is searching for a profiles.yml. Then, exit. This flag renders other debug step flags no-ops.",
     is_flag=True,
 )
 
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
@@ -102,13 +102,14 @@ def project_profile(self):
             return None
         return self.project.profile_name
 
-    def path_info(self):
-        open_cmd = dbt.clients.system.open_dir_cmd()
-        fire_event(OpenCommand(open_cmd=open_cmd, profiles_dir=self.profiles_dir))
-
     def run(self) -> bool:
+        # WARN: this is a legacy workflow that is not compatible with other runtime flags
         if self.args.config_dir:
-            self.path_info()
+            fire_event(
+                OpenCommand(
+                    open_cmd=dbt.clients.system.open_dir_cmd(), profiles_dir=str(self.profiles_dir)
+                )
+            )
             return DebugRunStatus.SUCCESS.value
 
         version: str = get_installed_version().to_version_string(skip_matcher=True)


Test patch: