Repository: pypa/pip
Pull request: fix-5963: fail elegantly
Fail elegantly on on missing name or section in config set / unset
Fixes #5963 


Problem statement:
Setting config value with --venv flag fails outside venv
**Environment**

* pip version: b47b2fa8
* Python version: 3.7.0
* OS: Debian unstable

I'm running inside a conda env, though that should not matter.

**Description**
Setting config value with `--venv` flag fails outside of a virtualenv:

```
Fatal Internal error [id=2]. Please report as a bug.
```

**Expected behavior**

Detect I'm outside a virtualenv and fail gracefully and with a sensible error message.

**How to Reproduce**

Run e.g. the following:
```
pip config --venv set isolated true
```

Hints from issue discussion:

Commit message: fix-5963: Add news file

Patch to review:
diff --git a/news/5963.bugfix b/news/5963.bugfix
new file mode 100644
index 00000000000..fcca0800a81
--- /dev/null
+++ b/news/5963.bugfix
@@ -0,0 +1 @@
+This change will fail elegantly on a missing name or section in config
diff --git a/src/pip/_internal/configuration.py b/src/pip/_internal/configuration.py
index b199fa7007d..783fa93f071 100644
--- a/src/pip/_internal/configuration.py
+++ b/src/pip/_internal/configuration.py
@@ -50,6 +50,12 @@ def _normalize_name(name):
 
 def _disassemble_key(name):
     # type: (str) -> List[str]
+    if "." not in name:
+        error_message = (
+            "Key does not contain dot separated section and key. "
+            "Perhaps you wanted to use 'global.{}' instead?"
+        ).format(name)
+        raise ConfigurationError(error_message)
     return name.split(".", 1)
 
 
diff --git a/tests/functional/test_configuration.py b/tests/functional/test_configuration.py
index de3828d6263..4c4e735871d 100644
--- a/tests/functional/test_configuration.py
+++ b/tests/functional/test_configuration.py
@@ -57,3 +57,6 @@ def test_listing_is_correct(self, script):
         """
 
         assert lines == textwrap.dedent(expected).strip().splitlines()
+
+    def test_forget_section(self, script):
+        script.pip("config", "set", "isolated", "true", expect_error=True)


Code review comments:
diff_hunk: @@ -57,3 +57,6 @@ def test_listing_is_correct(self, script):
         """
 
         assert lines == textwrap.dedent(expected).strip().splitlines()
+
+    def test_forget_section(self, script):
+        script.pip("config", "set", "isolated", "true", expect_error=True)
path: tests/functional/test_configuration.py
text: @user1:
You could check for the presence of `global.isolated` in `result.stderr`.