Skip to content

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

Open
wants to merge 9 commits into
base: dev/feature
Choose a base branch
from

Conversation

Absolutionism
Copy link
Contributor

@Absolutionism Absolutionism commented Apr 23, 2025

Description

This PR aims to add a RuntimeErrorCatcher allowing RuntimeErrors printed from RuntimeErrorManager to be caught and logged.
With this addition, allows for a SecCatchErrors and ExprCaughtErrors 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 way SecParse could maintain it's behavior.


Target Minecraft Versions: any
Requirements: none
Related Issues: #7766

@Absolutionism Absolutionism requested review from sovdeeth and a team as code owners April 23, 2025 01:20
@Absolutionism Absolutionism requested review from APickledWalrus and removed request for a team April 23, 2025 01:20
Copy link
Member

@sovdeeth sovdeeth left a 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

@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Apr 23, 2025
@Absolutionism Absolutionism requested a review from sovdeeth April 24, 2025 01:10
Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking better

@Absolutionism Absolutionism changed the title RuntimeLogHandler + Runtime Testing Elements RuntimeErrorCatcher + Runtime Elements Apr 24, 2025
@Absolutionism Absolutionism requested a review from sovdeeth April 24, 2025 02:52
Copy link
Member

@sovdeeth sovdeeth left a 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

@Absolutionism Absolutionism requested a review from sovdeeth April 24, 2025 21:19
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")
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

@Absolutionism Absolutionism requested a review from Efnilite April 29, 2025 18:54
Copy link
Member

@APickledWalrus APickledWalrus left a 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")
Copy link
Member

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.
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void addConsumers(RuntimeErrorConsumer ... newConsumers) {
public void addConsumers(RuntimeErrorConsumer... newConsumers) {


static {
Skript.registerExpression(ExprCaughtErrors.class, String.class, ExpressionType.SIMPLE,
"last caught [run[ ]time] errors");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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);
Copy link
Member

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() {
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants