From 920e1b6e2d154c2c483cede18f907e8f2fb98f3d Mon Sep 17 00:00:00 2001 From: Hertzole Date: Wed, 17 Jan 2024 18:29:24 +0100 Subject: [PATCH] refactor: ValueReference throws NotSupportedException if type is invalid --- .../Runtime/Values/ValueReference.cs | 4 +++- .../Tests/Runtime/BaseValueReferenceTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Packages/se.hertzole.scriptable-values/Runtime/Values/ValueReference.cs b/Packages/se.hertzole.scriptable-values/Runtime/Values/ValueReference.cs index a1be25c..6bba0f8 100644 --- a/Packages/se.hertzole.scriptable-values/Runtime/Values/ValueReference.cs +++ b/Packages/se.hertzole.scriptable-values/Runtime/Values/ValueReference.cs @@ -177,7 +177,7 @@ private T GetValue() $"Addressable asset is not loaded yet. Make sure you've called {nameof(LoadAddressableAssetAsync)} before trying to access the value."); #endif default: - throw new ArgumentOutOfRangeException(nameof(valueType), $"No supported value type for {valueType}."); + throw new NotSupportedException($"No supported value type for {valueType}."); } } @@ -202,6 +202,8 @@ private void SetValue(in T value, in bool notify) SetValueAddressable(value, notify); break; #endif + default: + throw new NotSupportedException($"No supported value type for {valueType}."); } } diff --git a/Packages/se.hertzole.scriptable-values/Tests/Runtime/BaseValueReferenceTest.cs b/Packages/se.hertzole.scriptable-values/Tests/Runtime/BaseValueReferenceTest.cs index c1cf7a8..ee366a9 100644 --- a/Packages/se.hertzole.scriptable-values/Tests/Runtime/BaseValueReferenceTest.cs +++ b/Packages/se.hertzole.scriptable-values/Tests/Runtime/BaseValueReferenceTest.cs @@ -226,7 +226,7 @@ public void InvalidType_Get() { TValue temp = instance.Value; } - catch (ArgumentOutOfRangeException) + catch (NotSupportedException) { gotError = true; } @@ -247,7 +247,7 @@ public void InvalidType_Set() { instance.Value = MakeDifferentValue(default); } - catch (ArgumentOutOfRangeException) + catch (NotSupportedException) { gotError = true; }