Repository: pybamm-team/PyBaMM (python)
Issue: Better error on unrecognised parameter set
Doing `pybamm.ParameterValues("bad")` gives `ValueError: Invalid Parameter Value`. It would be better to say something like `ValueError: 'bad' is not a recognised parameter set` and possibly list the valid options (including custom parameter sets that have been registered as entry points).
Pull request description: #4120 improved error message
# Description

Added a more informative error message when I passed an invalid parameter set, which rejects that parameter set and relays a list of potential paramters that could be inputted

Fixes #4120

## Type of change

Please add a line in the relevant section of [CHANGELOG.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CHANGELOG.md) to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

- [ ] New feature (non-breaking change which adds functionality)
- [ ] Optimization (back-end change that speeds up the code)
- [ ] Bug fix (non-breaking change which fixes an issue)

# Key checklist:

- [x] No style issues: `$ pre-commit run` (or `$ nox -s pre-commit`) (see [CONTRIBUTING.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) for how to set this up to run automatically when committing locally, in just two lines of code)
- [ ] All tests pass: `$ python run-tests.py --all` (or `$ nox -s tests`)
- [ ] The documentation builds: `$ python run-tests.py --doctest` (or `$ nox -s doctests`)

You can run integration tests, unit tests, and doctests together at once, using `$ python run-tests.py --quick` (or `$ nox -s quick`).

## Further checks:

- [x] Code is commented, particularly in hard-to-understand areas
- [ ] Tests added that prove fix is effective or that feature works


Patch:
diff --git a/pybamm/parameters/parameter_values.py b/pybamm/parameters/parameter_values.py
index c8011c735..57ebf6505 100644
--- a/pybamm/parameters/parameter_values.py
+++ b/pybamm/parameters/parameter_values.py
@@ -65,7 +65,10 @@ class ParameterValues:
                 values.pop("chemistry", None)
                 self.update(values, check_already_exists=False)
             else:
-                raise ValueError("Invalid Parameter Value")
+                valid_sets = "\n".join(pybamm.parameter_sets.keys())
+                raise ValueError(
+                    f"'{values}' is not a valid parameter set. Parameter set must be one of:\n{valid_sets}"
+                )
 
         # Initialise empty _processed_symbols dict (for caching)
         self._processed_symbols = {}


Test patch:
diff --git a/tests/unit/test_parameters/test_parameter_values.py b/tests/unit/test_parameters/test_parameter_values.py
index 7b5fd38bf..28b8aa2ef 100644
--- a/tests/unit/test_parameters/test_parameter_values.py
+++ b/tests/unit/test_parameters/test_parameter_values.py
@@ -43,7 +43,7 @@ class TestParameterValues(TestCase):
             pybamm.ParameterValues(None, chemistry="lithium-ion")
 
         # junk param values rejected
-        with self.assertRaisesRegex(ValueError, "Invalid Parameter Value"):
+        with self.assertRaisesRegex(ValueError, "'Junk' is not a valid parameter set."):
             pybamm.ParameterValues("Junk")
 
     def test_repr(self):