Skip to content

Commit

Permalink
Merge pull request #4672 from pybamm-team/fix-incorrect-error-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
aabills authored Dec 13, 2024
2 parents 62e8f3b + 864388f commit 1d303c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ def __getitem__(self, key):
) from error
best_matches = self.get_best_matches(key)
for k in best_matches:
if key in k and k.endswith("]"):
if key in k and k.endswith("]") and not key.endswith("]"):
raise KeyError(
f"'{key}' not found. Use the dimensional version '{k}' instead."
) from error
elif key in k and (
k.startswith("Primary") or k.startswith("Secondary")
):
raise KeyError(
f"'{key}' not found. If you are using a composite model, you may need to use {k} instead. Otherwise, best matches are {best_matches}"
) from error
raise KeyError(
f"'{key}' not found. Best matches are {best_matches}"
) from error
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_fuzzy_dict(self):
"Lithium plating current": 4,
"A dimensional variable [m]": 5,
"Positive particle diffusivity [m2.s-1]": 6,
"Primary: Open circuit voltage [V]": 7,
}
)
d2 = pybamm.FuzzyDict(
Expand All @@ -52,6 +53,9 @@ def test_fuzzy_dict(self):
with pytest.raises(KeyError, match="dimensional version"):
d.__getitem__("A dimensional variable")

with pytest.raises(KeyError, match="composite model"):
d.__getitem__("Open circuit voltage [V]")

with pytest.raises(KeyError, match="open circuit voltage"):
d.__getitem__("Measured open circuit voltage [V]")

Expand Down

0 comments on commit 1d303c9

Please sign in to comment.