From 9d87dbad9f0c649c8244586cfea3ca25731da893 Mon Sep 17 00:00:00 2001 From: tbreisacher Date: Tue, 25 Jul 2017 16:30:46 -0700 Subject: [PATCH] Produce an "internal compiler error" for Errors (such as StackOverFlowError), 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 --- src/com/google/javascript/jscomp/AbstractCompiler.java | 6 +++--- src/com/google/javascript/jscomp/Compiler.java | 2 +- src/com/google/javascript/jscomp/NodeTraversal.java | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/com/google/javascript/jscomp/AbstractCompiler.java b/src/com/google/javascript/jscomp/AbstractCompiler.java index fbdc1462a6e..994bc39e966 100644 --- a/src/com/google/javascript/jscomp/AbstractCompiler.java +++ b/src/com/google/javascript/jscomp/AbstractCompiler.java @@ -184,7 +184,7 @@ static enum MostRecentTypechecker { /** * Report an internal error. */ - abstract void throwInternalError(String msg, Exception cause); + abstract void throwInternalError(String msg, Throwable cause); /** * Gets the current coding convention. @@ -590,13 +590,13 @@ abstract void updateGlobalVarReferences(Map /** * 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 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 getDefaultDefineValues(); diff --git a/src/com/google/javascript/jscomp/Compiler.java b/src/com/google/javascript/jscomp/Compiler.java index b226f86851f..0db8a9a9408 100644 --- a/src/com/google/javascript/jscomp/Compiler.java +++ b/src/com/google/javascript/jscomp/Compiler.java @@ -2799,7 +2799,7 @@ public CheckLevel getErrorLevel(JSError error) { * Report an internal error. */ @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; RuntimeException e = new RuntimeException(finalMessage, cause); diff --git a/src/com/google/javascript/jscomp/NodeTraversal.java b/src/com/google/javascript/jscomp/NodeTraversal.java index 1a54086c148..0ac5ae80421 100644 --- a/src/com/google/javascript/jscomp/NodeTraversal.java +++ b/src/com/google/javascript/jscomp/NodeTraversal.java @@ -271,7 +271,7 @@ public NodeTraversal(AbstractCompiler compiler, Callback cb, this.useBlockScope = scopeCreator.hasBlockScope(); } - private void throwUnexpectedException(Exception unexpectedException) { + private void throwUnexpectedException(Throwable unexpectedException) { // If there's an unexpected exception, try to get the // line number of the code that caused it. String message = unexpectedException.getMessage(); @@ -307,7 +307,7 @@ public void traverse(Node root) { // null parent ensures that the shallow callbacks will traverse root traverseBranch(root, null); popScope(); - } catch (Exception unexpectedException) { + } catch (Error | Exception unexpectedException) { throwUnexpectedException(unexpectedException); } } @@ -326,7 +326,7 @@ void traverseRoots(Node externs, Node root) { traverseBranch(root, scopeRoot); popScope(); - } catch (Exception unexpectedException) { + } catch (Error | Exception unexpectedException) { throwUnexpectedException(unexpectedException); } } @@ -362,7 +362,7 @@ void traverseWithScope(Node root, Scope s) { pushScope(s); traverseBranch(root, null); popScope(); - } catch (Exception unexpectedException) { + } catch (Error | Exception unexpectedException) { throwUnexpectedException(unexpectedException); } } @@ -437,7 +437,7 @@ private void traverseScopeRoot(Node scopeRoot) { initScopeRoots(scopeRoot.getParent()); // null parent ensures that the shallow callbacks will traverse root traverseBranch(scopeRoot, scopeRoot.getParent()); - } catch (Exception unexpectedException) { + } catch (Error | Exception unexpectedException) { throwUnexpectedException(unexpectedException); } }