-
-
Notifications
You must be signed in to change notification settings - Fork 390
RuntimeErrorCatcher + Runtime Elements #7823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/feature
Are you sure you want to change the base?
RuntimeErrorCatcher + Runtime Elements #7823
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider if you want to keep these test-only or make them broadly available
src/main/java/ch/njol/skript/test/runner/ExprRuntimeErrors.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorManager.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking better
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few things
src/main/java/org/skriptlang/skript/log/runtime/RuntimeErrorCatcher.java
Outdated
Show resolved
Hide resolved
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Name("Catch Runtime Errors") | ||
@Description("Catch any runtime errors produced by code within the section. This is an in progress feature") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be an experiment then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the option to choose between making it an experiment or just adding an "in progress" in the description. I chose the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What might change here? I think syntax that is subject to change would best be put behind an experiment. It might not hurt here either since error catching is a "new" concept for Skript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly catching specific types of errors, but that shouldn't be breaking if added in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this idea, and it seems well implemented. Great work so far! Here is what I found.
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Name("Catch Runtime Errors") | ||
@Description("Catch any runtime errors produced by code within the section. This is an in progress feature") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What might change here? I think syntax that is subject to change would best be put behind an experiment. It might not hurt here either since error catching is a "new" concept for Skript.
consumers.addAll(Arrays.asList(newConsumers)); | ||
} | ||
} | ||
|
||
/** | ||
* Removes a {@link RuntimeErrorConsumer} from the tracked list. | ||
* @param consumer The consumer to remove. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs return value docs
* Consumers will be maintained when the manager is refreshed. | ||
* @param newConsumers The {@link RuntimeErrorConsumer}s to add. | ||
*/ | ||
public void addConsumers(RuntimeErrorConsumer ... newConsumers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void addConsumers(RuntimeErrorConsumer ... newConsumers) { | |
public void addConsumers(RuntimeErrorConsumer... newConsumers) { |
|
||
static { | ||
Skript.registerExpression(ExprCaughtErrors.class, String.class, ExpressionType.SIMPLE, | ||
"last caught [run[ ]time] errors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"last caught [run[ ]time] errors"); | |
"[the] last caught [run[ ]time] errors"); |
|
||
AtomicBoolean delayed = new AtomicBoolean(false); | ||
Runnable afterLoading = () -> delayed.set(!getParser().getHasDelayBefore().isFalse()); | ||
trigger = loadCode(sectionNode, "runtime", afterLoading, Event.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the event context is not changing, you should not load this code into a trigger. You can simply load it as normal and check the updated delay value in ParserInstance. As for walk
, to execute the section, you can do something like:
last.setNext(null);
TriggerItem.walk(first, event);
first
and last
are available from TriggerSection and represent the first and last elements of the section, respectively.
/** | ||
* Gets all the cached {@link RuntimeError}s. | ||
*/ | ||
public @Unmodifiable List<RuntimeError> getCachedErrors() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would annotate this more specifically as @UnmodifiableView
(per the docs on how the collections method functions)
Description
This PR aims to add a
RuntimeErrorCatcher
allowingRuntimeErrors
printed fromRuntimeErrorManager
to be caught and logged.With this addition, allows for a
SecCatchErrors
andExprCaughtErrors
to create code that catches errors, preventing them from being logged into terminal, and accessing the errors that were caught.In the related issue (by me), I realized that
SecParse
never ran the code within the section, so I decided to make a new section and expression that waySecParse
could maintain it's behavior.Target Minecraft Versions: any
Requirements: none
Related Issues: #7766