Repository: dbt-labs/dbt-core

Issue:
[CT-2607] [Bug] Invalid YAML dictionary error for warn-error-options references the `--vars` flag
### 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

Run `dbt --warn-error-options '' run -s doesntexist`
The error message is `  The --vars argument must be a YAML dictionary, but was of type 'NoneType'`- talking about the `--vars` argument instead of `--warn-error-options`. Looks like a lil copy-paste mistake. 

### Expected Behavior

The --warn-error-options argument must be a YAML dictionary, but was of type 'NoneType

### Steps To Reproduce

Above

### Relevant log output

_No response_

### Environment

```markdown
- OS: MacOS
- Python: Yes
- dbt: 1.5.0
```


### Which database adapter are you using with dbt?

_No response_

### Additional Context

_No response_


Discussion:

Resolving patch:
diff --git a/core/dbt/cli/option_types.py b/core/dbt/cli/option_types.py
--- a/core/dbt/cli/option_types.py
+++ b/core/dbt/cli/option_types.py
@@ -1,7 +1,7 @@
 from click import ParamType, Choice
 
-from dbt.config.utils import parse_cli_vars
-from dbt.exceptions import ValidationError
+from dbt.config.utils import parse_cli_yaml_string
+from dbt.exceptions import ValidationError, DbtValidationError, OptionNotYamlDictError
 
 from dbt.helper_types import WarnErrorOptions
 
@@ -16,8 +16,9 @@ def convert(self, value, param, ctx):
         if not isinstance(value, str):
             self.fail(f"Cannot load YAML from type {type(value)}", param, ctx)
         try:
-            return parse_cli_vars(value)
-        except ValidationError:
+            param_option_name = param.opts[0] if param.opts else param.name
+            return parse_cli_yaml_string(value, param_option_name.strip("-"))
+        except (ValidationError, DbtValidationError, OptionNotYamlDictError):
             self.fail(f"String '{value}' is not valid YAML", param, ctx)
 
 
diff --git a/core/dbt/config/utils.py b/core/dbt/config/utils.py
--- a/core/dbt/config/utils.py
+++ b/core/dbt/config/utils.py
@@ -19,6 +19,6 @@ def parse_cli_yaml_string(var_string: str, cli_option_name: str) -> Dict[str, An
             return cli_vars
         else:
             raise OptionNotYamlDictError(var_type, cli_option_name)
-    except DbtValidationError:
+    except (DbtValidationError, OptionNotYamlDictError):
         fire_event(InvalidOptionYAML(option_name=cli_option_name))
         raise


Test patch:
diff --git a/tests/unit/test_option_types.py b/tests/unit/test_option_types.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/test_option_types.py
@@ -0,0 +1,26 @@
+from click import Option, BadParameter
+import pytest
+
+from dbt.cli.option_types import YAML
+
+
+class TestYAML:
+    @pytest.mark.parametrize(
+        "raw_value,expected_converted_value",
+        [
+            ("{}", {}),
+            ("{'test_var_key': 'test_var_value'}", {"test_var_key": "test_var_value"}),
+        ],
+    )
+    def test_yaml_init(self, raw_value, expected_converted_value):
+        converted_value = YAML().convert(raw_value, Option(["--vars"]), None)
+        assert converted_value == expected_converted_value
+
+    @pytest.mark.parametrize(
+        "invalid_yaml_str",
+        ["{", ""],
+    )
+    def test_yaml_init_invalid_yaml_str(self, invalid_yaml_str):
+        with pytest.raises(BadParameter) as e:
+            YAML().convert(invalid_yaml_str, Option(["--vars"]), None)
+        assert "--vars" in e.value.format_message()