Skip to content

Commit

Permalink
- Changed the try/catch exceptions to Debug.LogException with a Debug…
Browse files Browse the repository at this point in the history
….LogError, to properly show the issues in the Unity console
  • Loading branch information
CoderGamester committed Oct 25, 2024
1 parent 87a8655 commit 02f93c4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.9.2] - 2024-10-25

**Fixed**
- Changed the try/catch exceptions to Debug.LogException with a Debug.LogError, to properly show the issues in the Unity console

## [0.9.1] - 2023-09-04

**Fixed**
- Added missing documentation to describe the purpose of the *InnerStateData* and *StateFactoryData* classes.

## [0.9.0] - 2023-09-02

- Introduced unique identifiers for *IWaitActivity* instances to differentiate between different activities
- Enhanced the *TaskWaitState* class with a new event queuing mechanism to handle events after task completion
- Improved the *SplitState* class to allow pausing/resuming of inner state transitions

**Changed**
- Updated exception handling across various classes, replacing *MissingMemberException* with *InvalidOperationException* for more appropriate error representation

## [0.8.0] - 2023-08-03

**Changed**
- Change the main class name from *Statemachine* to *Statechart* Change namespace to avoid conflicts to StatechartMachine
- Changed both *ISplitState* and *INestedState* to receive a single parameterized *NestedStateData* to make calls less verbose and ready for future scalability

## [0.7.0] - 2021-05-04

- Improved State documentations
Expand Down
28 changes: 24 additions & 4 deletions Runtime/Internal/StateInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ private void TriggerEnter(IStateInternal state)
}
catch (Exception e)
{
throw new Exception($"Exception in the state {state.Name}, OnEnter() actions.\n" + CreationStackTrace, e);
var finalMessage = "";
#if UNITY_EDITOR || DEBUG
finalMessage = $"\nStackTrace log of '{state.Name}' state creation bellow.\n{CreationStackTrace}";
#endif

Debug.LogError($"Exception in the state '{state.Name}', OnExit() actions.\n" +
$"-->> Check the exception log after this one for more details <<-- {finalMessage}");
Debug.LogException(e);
}
}

Expand All @@ -180,7 +187,14 @@ private void TriggerExit()
}
catch(Exception e)
{
throw new Exception($"Exception in the state '{Name}', OnExit() actions.\n" + CreationStackTrace, e);
var finalMessage = "";
#if UNITY_EDITOR || DEBUG
finalMessage = $"\nStackTrace log of '{Name}' state creation bellow.\n{CreationStackTrace}";
#endif

Debug.LogError($"Exception in the state '{Name}', OnExit() actions.\n" +
$"-->> Check the exception log after this one for more details <<-- {finalMessage}");
Debug.LogException(e);
}
}

Expand All @@ -199,8 +213,14 @@ private void TriggerTransition(ITransitionInternal transition, string eventName)
}
catch (Exception e)
{
throw new Exception($"Exception in the transition '{Name}' -> '{transition.TargetState?.Name}'," +
$" TriggerTransition() actions.\n{transition.CreationStackTrace}", e);
var finalMessage = "";
#if UNITY_EDITOR || DEBUG
finalMessage = $"\nStackTrace log of this transition creation bellow.\n{transition.CreationStackTrace}";
#endif

Debug.LogError($"Exception in the transition '{Name}' -> '{transition.TargetState?.Name}'" +
$"-->> Check the exception log after this one for more details <<-- {finalMessage}");
Debug.LogException(e);
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions Runtime/Internal/TaskWaitState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ private async Task InnerTaskAwait(string eventName)
}
catch (Exception e)
{
throw new Exception($"Exception in the state '{Name}', when calling the task wait action " +
$"'{_taskAwaitAction.Target}.{_taskAwaitAction.Method.Name}()'.\n" + CreationStackTrace, e);
var finalMessage = "";
#if UNITY_EDITOR || DEBUG
finalMessage = $"\nStackTrace log of '{Name}' state creation bellow.\n{CreationStackTrace}";
#endif

Debug.LogError($"Exception in the state '{Name}', when calling the task wait action" +
$"'{_taskAwaitAction.Target}.{_taskAwaitAction.Method.Name}()'.\n" +
$"-->> Check the exception log after this one for more details <<-- {finalMessage}");
Debug.LogException(e);
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions Runtime/Internal/WaitState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void Enter()
_waitingActivity = new WaitActivity(OnActivityComplete);
_triggered = false;

for(int i = 0; i < _onEnter.Count; i++)
for (int i = 0; i < _onEnter.Count; i++)
{
_onEnter[i]?.Invoke();
}
Expand All @@ -48,7 +48,7 @@ public override void Enter()
/// <inheritdoc />
public override void Exit()
{
for(int i = 0; i < _onExit.Count; i++)
for (int i = 0; i < _onExit.Count; i++)
{
_onExit[i]?.Invoke();
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public ITransition WaitingFor(Action<IWaitActivity> waitAction)

private void OnActivityComplete(uint id)
{
if(id == _waitingActivity.Id)
if (id == _waitingActivity.Id)
{
_stateFactory.Data.StateChartMoveNextCall(null);
}
Expand All @@ -143,7 +143,7 @@ protected override ITransitionInternal OnTrigger(IStatechartEvent statechartEven
{
if (statechartEvent != null && _events.TryGetValue(statechartEvent, out var transition))
{
if(transition.TargetState != null)
if (transition.TargetState != null)
{
_waitingActivity.ForceComplete();
}
Expand All @@ -167,14 +167,21 @@ private void InnerWait(string eventName)
if (IsStateLogsEnabled)
{
Debug.Log($"'{eventName}' event triggers the wait method '{_waitAction.Method.Name}'" +
$"from the object {_waitAction.Target} in the state {Name}");
$"from the object {_waitAction.Target} in the state {Name}");
}
_waitAction(_waitingActivity);
}
catch(Exception e)
catch (Exception e)
{
throw new Exception($"Exception in the state '{Name}', when calling the wait action {_waitAction.Method.Name}" +
$"from the object {_waitAction.Target}.\n" + CreationStackTrace, e);
var finalMessage = "";
#if UNITY_EDITOR || DEBUG
finalMessage = $"\nStackTrace log of '{Name}' state creation bellow.\n{CreationStackTrace}";
#endif

Debug.LogError($"Exception in the state '{Name}', when calling the wait action {_waitAction.Method.Name}" +
$" from the object {_waitAction.Target}.\n" +
$"-->> Check the exception log after this one for more details <<-- {finalMessage}");
Debug.LogException(e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "com.gamelovers.statechart",
"displayName": "Statechart",
"author": "Miguel Tomas",
"version": "0.9.1",
"unity": "2021.4",
"version": "0.9.2",
"unity": "2022.4",
"license": "MIT",
"description": "This package allows the use of Statecharts (Hierarchichal State Machine) within an Unity project.\n\nThe primary feature of Statecharts is that states can be organized in a hierarchy.\nA Statecharts is a state machine where each state in the state machine may define its own subordinate state machines, called substates.\nThose states can again define substates.\n\nFor more information: https://statecharts.github.io/what-is-a-statechart.html",
"type": "library",
Expand Down

0 comments on commit 02f93c4

Please sign in to comment.