Skip to content
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

feat: log some ClassCastExceptions for better troubleshooting #756

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@
*/
package org.eclipse.tm4e.core.internal.grammar.raw;

import java.lang.System.Logger;
import java.lang.System.Logger.Level;

import org.eclipse.tm4e.core.internal.parser.PropertySettable;

final class RawCaptures extends PropertySettable.HashMap<IRawRule> implements IRawCaptures {

private static final Logger LOGGER = System.getLogger(RawCaptures.class.getName());

private static final long serialVersionUID = 1L;

@Override
public IRawRule getCapture(final String captureId) {
return get(captureId);
try {
return get(captureId);
} catch (final ClassCastException ex) {
// log ClassCastException with some context, to better troubleshoot issues like https://github.com/eclipse/tm4e/issues/754
LOGGER.log(Level.ERROR, "Unexpected ClassCastException in RawCaptures.getCapture(\"" + captureId + "\")", ex);
throw ex;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
*/
package org.eclipse.tm4e.core.internal.grammar.raw;

import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.NoSuchElementException;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tm4e.core.internal.parser.PropertySettable;

public final class RawRepository extends PropertySettable.HashMap<IRawRule> implements IRawRepository {

private static final Logger LOGGER = System.getLogger(RawRepository.class.getName());

private static final long serialVersionUID = 1L;

public static final String DOLLAR_BASE = "$base";
Expand All @@ -35,7 +39,13 @@ private IRawRule getSafe(final String key) {
@Override
@Nullable
public IRawRule getRule(final String name) {
return get(name);
try {
return get(name);
} catch (final ClassCastException ex) {
// log ClassCastException with some context, to better troubleshoot issues like https://github.com/eclipse/tm4e/issues/754
LOGGER.log(Level.ERROR, "Unexpected ClassCastException in RawRepository.getRule(\"" + name + "\")", ex);
throw ex;
}
}

@Override
Expand Down
Loading