Skip to content

Commit d82c22c

Browse files
change on_error to only return message
1 parent 732631b commit d82c22c

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

Code/ContextSystem/Contexts/Control/AttemptStatement.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using SER.Code.ContextSystem.BaseContexts;
33
using SER.Code.ContextSystem.Interfaces;
44
using SER.Code.ContextSystem.Structures;
5-
using SER.Code.Extensions;
65
using SER.Code.Helpers.ResultSystem;
76
using SER.Code.TokenSystem.Tokens;
87

@@ -12,10 +11,10 @@ namespace SER.Code.ContextSystem.Contexts.Control;
1211
public class AttemptStatement : StatementContext, IExtendableStatement, IKeywordContext
1312
{
1413
public string KeywordName => "attempt";
15-
public string Description => "Runs everything inside the statement, and if something throws an exception (error), " +
16-
"the statement skips everything after it and jumps straight to the " +
17-
$"{typeof(OnErrorStatement).FriendlyTypeName(true)} " +
18-
"after it if provided.";
14+
public string Description =>
15+
"Runs everything inside the statement, and if something throws an exception (error), the error will not " +
16+
"terminate the script. If there is an 'on_error' statement, it will be executed.";
17+
1918
public string[] Arguments => [];
2019
public string? Example =>
2120
"""

Code/ContextSystem/Contexts/Control/OnErrorStatement.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,28 @@
88
using SER.Code.TokenSystem.Tokens.VariableTokens;
99
using SER.Code.ValueSystem;
1010
using SER.Code.VariableSystem.Bases;
11-
using SER.Code.VariableSystem.Variables;
1211

1312
namespace SER.Code.ContextSystem.Contexts.Control;
1413

1514
[UsedImplicitly]
1615
public class OnErrorStatement : StatementContext, IStatementExtender, IKeywordContext, IAcceptOptionalVariableDefinitionsContext
1716
{
1817
public string KeywordName => "on_error";
19-
public string Description => "Catches an exception thrown inside of a " +
20-
typeof(AttemptStatement).FriendlyTypeName(true);
18+
public string Description =>
19+
$"Catches an exception thrown inside of a {typeof(AttemptStatement).FriendlyTypeName(true)}";
20+
2121
public string[] Arguments => [];
22-
public string? Example =>
22+
public string Example =>
2323
"""
2424
&collection = EmptyCollection
2525
attempt
2626
Print {CollectionFetch &collection 2}
27-
# throws because there's nothing at index 2
27+
# ERROR: there's nothing at index 2
2828
on_error
29-
with *exception
29+
with $message
3030
31-
Print "Error!: {ExceptionInfo *exception message}"
31+
# this will print the error message
32+
Print "Error: {$message}"
3233
end
3334
""";
3435

@@ -45,8 +46,7 @@ public Exception? Exception
4546
field = value;
4647
}
4748
}
48-
private VariableToken? _variableToken;
49-
private Variable? _variable;
49+
private LiteralVariableToken? _variableToken;
5050

5151
public override TryAddTokenRes TryAddToken(BaseToken token)
5252
{
@@ -62,29 +62,29 @@ public Result SetOptionalVariables(params VariableToken[] variableTokens)
6262
{
6363
if (variableTokens.Length > 1)
6464
return $"Too many arguments provided for {FriendlyName}, only 1 is allowed.";
65-
var token = variableTokens.FirstOrDefault();
66-
if (token is null) return true;
6765

68-
if (token is not ReferenceVariableToken)
69-
return $"Variable {token.RawRepr} cannot be used for a {FriendlyName} as it's not a " +
70-
$"{typeof(ReferenceVariable).FriendlyTypeName(true)}.";
66+
if (variableTokens.First() is not LiteralVariableToken token)
67+
{
68+
return $"{FriendlyName} only accepts a literal variable.";
69+
}
7170

7271
_variableToken = token;
7372
return true;
7473
}
7574

7675
protected override IEnumerator<float> Execute()
7776
{
77+
Variable? variable = null;
7878
if (_variableToken is not null)
7979
{
80-
_variable = Variable.Create(_variableToken.Name, Value.Parse(Exception!, Script));
81-
Script.AddLocalVariable(_variable);
80+
variable = Variable.Create(_variableToken.Name, Value.Parse(Exception!.Message, Script));
81+
Script.AddLocalVariable(variable);
8282
}
8383

8484
var coro = RunChildren();
8585
while (coro.MoveNext())
8686
yield return coro.Current;
8787

88-
if (_variable is not null) Script.RemoveLocalVariable(_variable);
88+
if (variable is not null) Script.RemoveLocalVariable(variable);
8989
}
9090
}

Code/MethodSystem/Methods/PlayerVariableMethods/OverlappingMethod.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using JetBrains.Annotations;
2-
using LabApi.Features.Wrappers;
32
using SER.Code.ArgumentSystem.Arguments;
43
using SER.Code.ArgumentSystem.BaseArguments;
54
using SER.Code.MethodSystem.BaseMethods.Synchronous;

Code/TokenSystem/Tokens/VariableTokens/LiteralVariableToken.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using SER.Code.ContextSystem.BaseContexts;
22
using SER.Code.ContextSystem.Contexts.VariableDefinition;
3-
using SER.Code.Helpers.ResultSystem;
43
using SER.Code.ScriptSystem;
54
using SER.Code.ValueSystem;
65
using SER.Code.VariableSystem.Variables;

Code/VariableSystem/Variables/LiteralVariable.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SER.Code.Extensions;
2-
using SER.Code.Helpers.ResultSystem;
32
using SER.Code.ValueSystem;
43
using SER.Code.VariableSystem.Bases;
54

0 commit comments

Comments
 (0)