Skip to content

Commit

Permalink
feat: log some ClassCastExceptions for better troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed May 22, 2024
1 parent b6ea4b4 commit 99e8ab0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit 99e8ab0

Please sign in to comment.