Skip to content

Commit

Permalink
Produce an "internal compiler error" for Errors (such as StackOverFlo…
Browse files Browse the repository at this point in the history
…wError), not just Exceptions

This makes it much easier to debug when a StackOverflowError happens

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=163140994
  • Loading branch information
tbreisacher authored and brad4d committed Jul 26, 2017
1 parent 3fcb04e commit 9d87dba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/AbstractCompiler.java
Expand Up @@ -184,7 +184,7 @@ static enum MostRecentTypechecker {
/** /**
* Report an internal error. * Report an internal error.
*/ */
abstract void throwInternalError(String msg, Exception cause); abstract void throwInternalError(String msg, Throwable cause);


/** /**
* Gets the current coding convention. * Gets the current coding convention.
Expand Down Expand Up @@ -590,13 +590,13 @@ abstract void updateGlobalVarReferences(Map<Var, ReferenceCollection>


/** /**
* Stores a map of default @define values. These values * Stores a map of default @define values. These values
* can be overriden by values specifically set in the CompilerOptions. * can be overridden by values specifically set in the CompilerOptions.
*/ */
abstract void setDefaultDefineValues(ImmutableMap<String, Node> values); abstract void setDefaultDefineValues(ImmutableMap<String, Node> values);


/** /**
* Gets a map of default @define values. These values * Gets a map of default @define values. These values
* can be overriden by values specifically set in the CompilerOptions. * can be overridden by values specifically set in the CompilerOptions.
*/ */
abstract ImmutableMap<String, Node> getDefaultDefineValues(); abstract ImmutableMap<String, Node> getDefaultDefineValues();


Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -2799,7 +2799,7 @@ public CheckLevel getErrorLevel(JSError error) {
* Report an internal error. * Report an internal error.
*/ */
@Override @Override
void throwInternalError(String message, Exception cause) { void throwInternalError(String message, Throwable cause) {
String finalMessage = "INTERNAL COMPILER ERROR.\nPlease report this problem.\n\n" + message; String finalMessage = "INTERNAL COMPILER ERROR.\nPlease report this problem.\n\n" + message;


RuntimeException e = new RuntimeException(finalMessage, cause); RuntimeException e = new RuntimeException(finalMessage, cause);
Expand Down
10 changes: 5 additions & 5 deletions src/com/google/javascript/jscomp/NodeTraversal.java
Expand Up @@ -271,7 +271,7 @@ public NodeTraversal(AbstractCompiler compiler, Callback cb,
this.useBlockScope = scopeCreator.hasBlockScope(); this.useBlockScope = scopeCreator.hasBlockScope();
} }


private void throwUnexpectedException(Exception unexpectedException) { private void throwUnexpectedException(Throwable unexpectedException) {
// If there's an unexpected exception, try to get the // If there's an unexpected exception, try to get the
// line number of the code that caused it. // line number of the code that caused it.
String message = unexpectedException.getMessage(); String message = unexpectedException.getMessage();
Expand Down Expand Up @@ -307,7 +307,7 @@ public void traverse(Node root) {
// null parent ensures that the shallow callbacks will traverse root // null parent ensures that the shallow callbacks will traverse root
traverseBranch(root, null); traverseBranch(root, null);
popScope(); popScope();
} catch (Exception unexpectedException) { } catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException); throwUnexpectedException(unexpectedException);
} }
} }
Expand All @@ -326,7 +326,7 @@ void traverseRoots(Node externs, Node root) {
traverseBranch(root, scopeRoot); traverseBranch(root, scopeRoot);


popScope(); popScope();
} catch (Exception unexpectedException) { } catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException); throwUnexpectedException(unexpectedException);
} }
} }
Expand Down Expand Up @@ -362,7 +362,7 @@ void traverseWithScope(Node root, Scope s) {
pushScope(s); pushScope(s);
traverseBranch(root, null); traverseBranch(root, null);
popScope(); popScope();
} catch (Exception unexpectedException) { } catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException); throwUnexpectedException(unexpectedException);
} }
} }
Expand Down Expand Up @@ -437,7 +437,7 @@ private void traverseScopeRoot(Node scopeRoot) {
initScopeRoots(scopeRoot.getParent()); initScopeRoots(scopeRoot.getParent());
// null parent ensures that the shallow callbacks will traverse root // null parent ensures that the shallow callbacks will traverse root
traverseBranch(scopeRoot, scopeRoot.getParent()); traverseBranch(scopeRoot, scopeRoot.getParent());
} catch (Exception unexpectedException) { } catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException); throwUnexpectedException(unexpectedException);
} }
} }
Expand Down

0 comments on commit 9d87dba

Please sign in to comment.