From 5c192954b7864c34721608f9d9ae40062ee595b3 Mon Sep 17 00:00:00 2001 From: Thomas Baumann <39156931+brownbaerchen@users.noreply.github.com> Date: Mon, 8 Jun 2026 14:59:04 +0200 Subject: [PATCH 1/2] Tell people what device they tried to use if it's not available --- heat/core/devices.py | 4 +++- tests/core/test_devices.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/heat/core/devices.py b/heat/core/devices.py index 83a2be05c6..ff4408764e 100644 --- a/heat/core/devices.py +++ b/heat/core/devices.py @@ -189,7 +189,9 @@ def sanitize_device(device: Optional[Union[str, Device]] = None) -> Device: try: return __device_mapping[device.strip().lower()] except (AttributeError, KeyError, TypeError): - raise ValueError(f"Unknown device, must be one of {', '.join(__device_mapping.keys())}") + raise ValueError( + f"Unknown device {device!r}, must be one of {', '.join(__device_mapping.keys())}" + ) def use_device(device: Optional[Union[str, Device]] = None) -> None: diff --git a/tests/core/test_devices.py b/tests/core/test_devices.py index 0d76ae053c..c8a09c518b 100644 --- a/tests/core/test_devices.py +++ b/tests/core/test_devices.py @@ -1,5 +1,6 @@ import os import unittest +import pytest import heat as ht from heat.testing.basic_test import TestCase @@ -72,3 +73,9 @@ def test_set_default_device_gpu(self): ht.use_device("fpu") with self.assertRaises(ValueError): ht.use_device(1) + + +def test_unknown_device_error_message(): + device_name = "Sauron's Eye" + with pytest.raises(ValueError, match=device_name): + ht.use_device(device_name) From 5efb02888acfffab10cb58274506b40c6c3d9a6f Mon Sep 17 00:00:00 2001 From: Thomas Saupe <39156931+brownbaerchen@users.noreply.github.com> Date: Wed, 10 Jun 2026 09:35:32 +0200 Subject: [PATCH 2/2] Update heat/core/devices.py Co-authored-by: Michael Tarnawa <18899420+mtar@users.noreply.github.com> --- heat/core/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/core/devices.py b/heat/core/devices.py index ff4408764e..0fb32a9282 100644 --- a/heat/core/devices.py +++ b/heat/core/devices.py @@ -190,7 +190,7 @@ def sanitize_device(device: Optional[Union[str, Device]] = None) -> Device: return __device_mapping[device.strip().lower()] except (AttributeError, KeyError, TypeError): raise ValueError( - f"Unknown device {device!r}, must be one of {', '.join(__device_mapping.keys())}" + f"Unknown device {device!r}, must be one of {tuple(__device_mapping.keys())}" )