* Backport StackUtils class from Helma 2.
* Implement jsStackTrace option to generate pure JS stack traces in error dumps.
This commit is contained in:
parent
bfdd643a99
commit
54ab7ca121
2 changed files with 54 additions and 2 deletions
|
@ -1366,8 +1366,13 @@ public final class Application implements Runnable {
|
|||
if (eventLog == null) {
|
||||
eventLog = getLogger(eventLogName);
|
||||
}
|
||||
|
||||
eventLog.error(msg, error);
|
||||
if ("true".equalsIgnoreCase(props.getProperty("jsStackTrace"))) {
|
||||
Exception jsx = new RuntimeException(error);
|
||||
StackUtils.setJavaScriptStack(error, jsx);
|
||||
eventLog.error(msg, jsx);
|
||||
} else {
|
||||
eventLog.error(msg, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
47
src/helma/util/StackUtils.java
Normal file
47
src/helma/util/StackUtils.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2006 Hannes Wallnoefer <hannes@helma.at>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package helma.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Utility class to extract pure JavaScript stack trace from Java exceptions
|
||||
*/
|
||||
public class StackUtils {
|
||||
|
||||
/**
|
||||
* Extract the JavaScript stack trace element from the source exception
|
||||
* and copy them over to the target exception.
|
||||
* @param source the source exception
|
||||
* @param target the target excepiton
|
||||
*/
|
||||
public static void setJavaScriptStack(Throwable source, Throwable target) {
|
||||
List list = new ArrayList();
|
||||
StackTraceElement[] stack = source.getStackTrace();
|
||||
for (int i = 0; i < stack.length; i++) {
|
||||
StackTraceElement e = stack[i];
|
||||
String name = e.getFileName();
|
||||
if (e.getLineNumber() > -1 &&
|
||||
(name.endsWith(".js") || name.endsWith(".hac"))) {
|
||||
list.add(e);
|
||||
}
|
||||
}
|
||||
target.setStackTrace((StackTraceElement[]) list.toArray(new StackTraceElement[list.size()]));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue