Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit bacac92

Browse files
committed
Show InputField for exceptions to view/copy full exception
1 parent 4e3d3a2 commit bacac92

File tree

8 files changed

+58
-61
lines changed

8 files changed

+58
-61
lines changed

src/CacheObject/CacheConstructor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ protected override object TryEvaluate()
7272
else
7373
ret = Activator.CreateInstance(returnType, ArgumentUtility.EmptyArgs);
7474

75-
HadException = false;
7675
LastException = null;
7776
return ret;
7877
}
7978
catch (Exception ex)
8079
{
81-
HadException = true;
8280
LastException = ex;
8381
return null;
8482
}

src/CacheObject/CacheField.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ protected override object TryEvaluate()
3232
try
3333
{
3434
var ret = FieldInfo.GetValue(DeclaringInstance);
35-
HadException = false;
3635
LastException = null;
3736
return ret;
3837
}
3938
catch (Exception ex)
4039
{
41-
HadException = true;
4240
LastException = ex;
4341
return null;
4442
}

src/CacheObject/CacheMethod.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ protected override object TryEvaluate()
4545
ret = methodInfo.Invoke(DeclaringInstance, Evaluator.TryParseArguments());
4646
else
4747
ret = methodInfo.Invoke(DeclaringInstance, ArgumentUtility.EmptyArgs);
48-
HadException = false;
4948
LastException = null;
5049
return ret;
5150
}
5251
catch (Exception ex)
5352
{
54-
HadException = true;
5553
LastException = ex;
5654
return null;
5755
}

src/CacheObject/CacheObjectBase.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public abstract class CacheObjectBase
5757
public abstract bool ShouldAutoEvaluate { get; }
5858
public abstract bool HasArguments { get; }
5959
public abstract bool CanWrite { get; }
60-
public bool HadException { get; protected set; }
6160
public Exception LastException { get; protected set; }
6261

6362
public virtual void SetFallbackType(Type fallbackType)
@@ -106,8 +105,8 @@ public void SetUserValue(object value)
106105
if (CellView != null)
107106
SetDataToCell(CellView);
108107

109-
// If the owner's parent CacheObject is set, we are setting the value of an inspected struct.
110-
// Set the inspector target as the value back to that parent cacheobject.
108+
// If the owner's ParentCacheObject is set, we are setting the value of an inspected struct.
109+
// Set the inspector target as the value back to that parent.
111110
if (Owner.ParentCacheObject != null)
112111
Owner.ParentCacheObject.SetUserValue(Owner.Target);
113112
}
@@ -137,7 +136,7 @@ protected virtual void ProcessOnEvaluate()
137136
{
138137
var prevState = State;
139138

140-
if (HadException)
139+
if (LastException != null)
141140
{
142141
LastValueWasNull = true;
143142
LastValueType = FallbackType;
@@ -158,7 +157,7 @@ protected virtual void ProcessOnEvaluate()
158157
{
159158
// If we changed states (always needs IValue change)
160159
// or if the value is null, and the fallback type isnt string (we always want to edit strings).
161-
if (State != prevState || (State != ValueState.String && Value.IsNullOrDestroyed()))
160+
if (State != prevState || (State != ValueState.String && State != ValueState.Exception && Value.IsNullOrDestroyed()))
162161
{
163162
// need to return IValue
164163
ReleaseIValue();
@@ -206,7 +205,7 @@ protected string GetValueLabel()
206205
return $"<i>{NOT_YET_EVAL} ({SignatureHighlighter.Parse(FallbackType, true)})</i>";
207206

208207
case ValueState.Exception:
209-
return $"<i><color=red>{LastException.ReflectionExToString()}</color></i>";
208+
return $"<i><color=#eb4034>{LastException.ReflectionExToString()}</color></i>";
210209

211210
// bool and number dont want the label for the value at all
212211
case ValueState.Boolean:
@@ -291,36 +290,36 @@ public virtual void SetDataToCell(CacheObjectCell cell)
291290
switch (State)
292291
{
293292
case ValueState.Exception:
294-
SetValueState(cell, ValueStateArgs.Default);
293+
SetValueState(cell, new(true, subContentButtonActive: true));
295294
break;
296295
case ValueState.Boolean:
297-
SetValueState(cell, new ValueStateArgs(false, toggleActive: true, applyActive: CanWrite));
296+
SetValueState(cell, new(false, toggleActive: true, applyActive: CanWrite));
298297
break;
299298
case ValueState.Number:
300-
SetValueState(cell, new ValueStateArgs(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
299+
SetValueState(cell, new(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
301300
break;
302301
case ValueState.String:
303302
if (LastValueWasNull)
304-
SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: true));
303+
SetValueState(cell, new(true, subContentButtonActive: true));
305304
else
306-
SetValueState(cell, new ValueStateArgs(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
305+
SetValueState(cell, new(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
307306
break;
308307
case ValueState.Enum:
309-
SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: CanWrite));
308+
SetValueState(cell, new(true, subContentButtonActive: CanWrite));
310309
break;
311310
case ValueState.Color:
312311
case ValueState.ValueStruct:
313312
if (ParseUtility.CanParse(LastValueType))
314-
SetValueState(cell, new ValueStateArgs(false, false, null, true, false, true, CanWrite, true, true));
313+
SetValueState(cell, new(false, false, null, true, false, true, CanWrite, true, true));
315314
else
316-
SetValueState(cell, new ValueStateArgs(true, inspectActive: true, subContentButtonActive: true));
315+
SetValueState(cell, new(true, inspectActive: true, subContentButtonActive: true));
317316
break;
318317
case ValueState.Collection:
319318
case ValueState.Dictionary:
320-
SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
319+
SetValueState(cell, new(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
321320
break;
322321
case ValueState.Unsupported:
323-
SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull));
322+
SetValueState(cell, new (true, inspectActive: !LastValueWasNull));
324323
break;
325324
}
326325

@@ -368,8 +367,10 @@ protected virtual void SetValueState(CacheObjectCell cell, ValueStateArgs args)
368367
if (cell.InspectButton != null)
369368
cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull);
370369

371-
// allow IValue for null strings though
372-
cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String));
370+
// set subcontent button if needed, and for null strings and exceptions
371+
cell.SubContentButton.Component.gameObject.SetActive(
372+
args.subContentButtonActive
373+
&& (!LastValueWasNull || State == ValueState.String || State == ValueState.Exception));
373374
}
374375

375376
// CacheObjectCell Apply
@@ -401,7 +402,7 @@ public virtual void OnCellSubContentToggle()
401402
{
402403
if (this.IValue == null)
403404
{
404-
var ivalueType = InteractiveValue.GetIValueTypeForState(State);
405+
Type ivalueType = InteractiveValue.GetIValueTypeForState(State);
405406

406407
if (ivalueType == null)
407408
return;
@@ -455,6 +456,7 @@ internal static GameObject InactiveIValueHolder
455456
{
456457
inactiveIValueHolder = new GameObject("Temp_IValue_Holder");
457458
GameObject.DontDestroyOnLoad(inactiveIValueHolder);
459+
inactiveIValueHolder.hideFlags = HideFlags.HideAndDontSave;
458460
inactiveIValueHolder.transform.parent = UniversalUI.PoolHolder.transform;
459461
inactiveIValueHolder.SetActive(false);
460462
}
@@ -467,9 +469,20 @@ internal static GameObject InactiveIValueHolder
467469

468470
public struct ValueStateArgs
469471
{
470-
public ValueStateArgs(bool valueActive = true, bool valueRichText = true, Color? valueColor = null,
471-
bool typeLabelActive = false, bool toggleActive = false, bool inputActive = false, bool applyActive = false,
472-
bool inspectActive = false, bool subContentButtonActive = false)
472+
public static ValueStateArgs Default { get; } = new(true);
473+
474+
public Color valueColor;
475+
public bool valueActive, valueRichText, typeLabelActive, toggleActive, inputActive, applyActive, inspectActive, subContentButtonActive;
476+
477+
public ValueStateArgs(bool valueActive = true,
478+
bool valueRichText = true,
479+
Color? valueColor = null,
480+
bool typeLabelActive = false,
481+
bool toggleActive = false,
482+
bool inputActive = false,
483+
bool applyActive = false,
484+
bool inspectActive = false,
485+
bool subContentButtonActive = false)
473486
{
474487
this.valueActive = valueActive;
475488
this.valueRichText = valueRichText;
@@ -481,14 +494,6 @@ public ValueStateArgs(bool valueActive = true, bool valueRichText = true, Color?
481494
this.inspectActive = inspectActive;
482495
this.subContentButtonActive = subContentButtonActive;
483496
}
484-
485-
public static ValueStateArgs Default => _default;
486-
private static ValueStateArgs _default = new ValueStateArgs(true);
487-
488-
public bool valueActive, valueRichText, typeLabelActive, toggleActive,
489-
inputActive, applyActive, inspectActive, subContentButtonActive;
490-
491-
public Color valueColor;
492497
}
493498
}
494499
}

src/CacheObject/CacheProperty.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ protected override object TryEvaluate()
4040
ret = PropertyInfo.GetValue(DeclaringInstance, this.Evaluator.TryParseArguments());
4141
else
4242
ret = PropertyInfo.GetValue(DeclaringInstance, null);
43-
HadException = false;
4443
LastException = null;
4544
return ret;
4645
}
4746
catch (Exception ex)
4847
{
49-
HadException = true;
5048
LastException = ex;
5149
return null;
5250
}

src/CacheObject/IValues/InteractiveString.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public override void OnBorrowed(CacheObjectBase owner)
3131
{
3232
base.OnBorrowed(owner);
3333

34-
inputField.Component.readOnly = !owner.CanWrite;
35-
ApplyButton.Component.gameObject.SetActive(owner.CanWrite);
34+
bool canWrite = owner.CanWrite && owner.State != ValueState.Exception;
35+
inputField.Component.readOnly = !canWrite;
36+
ApplyButton.Component.gameObject.SetActive(canWrite);
3637

3738
SaveFilePath.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, "untitled.txt");
3839
}
@@ -47,6 +48,9 @@ private bool IsStringTooLong(string s)
4748

4849
public override void SetValue(object value)
4950
{
51+
if (CurrentOwner.State == ValueState.Exception)
52+
value = CurrentOwner.LastException.ToString();
53+
5054
RealValue = value as string;
5155
SaveFileRow.SetActive(IsStringTooLong(RealValue));
5256

src/CacheObject/IValues/InteractiveValue.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,45 @@ public abstract class InteractiveValue : IPooledObject
1616
{
1717
public static Type GetIValueTypeForState(ValueState state)
1818
{
19-
switch (state)
19+
return state switch
2020
{
21-
case ValueState.String:
22-
return typeof(InteractiveString);
23-
case ValueState.Enum:
24-
return typeof(InteractiveEnum);
25-
case ValueState.Collection:
26-
return typeof(InteractiveList);
27-
case ValueState.Dictionary:
28-
return typeof(InteractiveDictionary);
29-
case ValueState.ValueStruct:
30-
return typeof(InteractiveValueStruct);
31-
case ValueState.Color:
32-
return typeof(InteractiveColor);
33-
default: return null;
34-
}
21+
ValueState.Exception or ValueState.String => typeof(InteractiveString),
22+
ValueState.Enum => typeof(InteractiveEnum),
23+
ValueState.Collection => typeof(InteractiveList),
24+
ValueState.Dictionary => typeof(InteractiveDictionary),
25+
ValueState.ValueStruct => typeof(InteractiveValueStruct),
26+
ValueState.Color => typeof(InteractiveColor),
27+
_ => null,
28+
};
3529
}
3630

3731
public GameObject UIRoot { get; set; }
3832
public float DefaultHeight => -1f;
3933

4034
public virtual bool CanWrite => this.CurrentOwner.CanWrite;
4135

42-
public CacheObjectBase CurrentOwner => m_owner;
43-
private CacheObjectBase m_owner;
36+
public CacheObjectBase CurrentOwner => owner;
37+
private CacheObjectBase owner;
4438

4539
public bool PendingValueWanted;
4640

4741
public virtual void OnBorrowed(CacheObjectBase owner)
4842
{
49-
if (this.m_owner != null)
43+
if (this.owner != null)
5044
{
5145
ExplorerCore.LogWarning("Setting an IValue's owner but there is already one set. Maybe it wasn't cleaned up?");
5246
ReleaseFromOwner();
5347
}
5448

55-
this.m_owner = owner;
49+
this.owner = owner;
5650
}
5751

5852
public virtual void ReleaseFromOwner()
5953
{
60-
if (this.m_owner == null)
54+
if (this.owner == null)
6155
return;
6256

63-
this.m_owner = null;
57+
this.owner = null;
6458
}
6559

6660
public abstract void SetValue(object value);

src/Tests/TestClass.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static TestClass()
2828

2929
public static object LiterallyAnything = null;
3030

31+
public static string Exception => throw new Exception("This is a test.");
32+
3133
// Test enumerables
3234
public static int[,,] MultiDimensionalArray = new int[45, 45, 45];
3335
public static List<object> ListOfInts;

0 commit comments

Comments
 (0)