PyAPI: throw exception when cycles is given an invalid device name

This commit is contained in:
2020-10-15 16:35:41 +11:00
parent c0dde8be84
commit 4bea4702d5

View File

@@ -410,6 +410,11 @@ static PyObject *available_devices_func(PyObject * /*self*/, PyObject *args)
} }
DeviceType type = Device::type_from_string(type_name); DeviceType type = Device::type_from_string(type_name);
if ((type == DEVICE_NONE) && (type_name[0] != '\0')) {
PyErr_Format(PyExc_ValueError, "Device \"%s\" not known.", type_name);
return NULL;
}
uint mask = (type == DEVICE_NONE) ? DEVICE_MASK_ALL : DEVICE_MASK(type); uint mask = (type == DEVICE_NONE) ? DEVICE_MASK_ALL : DEVICE_MASK(type);
mask |= DEVICE_MASK_CPU; mask |= DEVICE_MASK_CPU;