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

Show output up to the point when an error is thrown. #76

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 @@ -17,8 +17,6 @@

<div id="script-editor" class="ace_editor_wrapper"></div>

<pre id="stacktrace" class="alert-danger" style="display: none;"></pre>

<div id="result" class="alert alert-success" role="alert" style="display: none;">
<h6>Result</h6>
<pre></pre>
Expand All @@ -38,6 +36,8 @@ <h6>Output</h6>
<pre></pre>
</div>

<pre id="stacktrace" class="alert-danger" style="display: none;"></pre>

<div id="running-time" class="alert alert-info" role="alert" style="display: none;">
<h6>Running Time</h6>
<pre></pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ var GroovyConsole = function () {
var runningTime = response.runningTime;

if (exceptionStackTrace && exceptionStackTrace.length) {
if (output && output.length) {
$('#output pre').text(output);
$('#output').removeClass('alert-success')
.addClass('alert-danger')
.fadeIn('fast');
}
$('#stacktrace').text(exceptionStackTrace).fadeIn('fast');
} else {
if (!GroovyConsole.showTable(response) && result && result.length) {
Expand All @@ -229,7 +235,9 @@ var GroovyConsole = function () {

if (output && output.length) {
$('#output pre').text(output);
$('#output').fadeIn('fast');
$('#output').removeClass('alert-danger')
.addClass('alert-success')
.fadeIn('fast');
}

if (runningTime && runningTime.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class DefaultAuditService implements AuditService {

if (response.exceptionStackTrace) {
auditRecordNode.setProperty(AuditRecord.PROPERTY_EXCEPTION_STACK_TRACE, response.exceptionStackTrace)

if (response.output) {
auditRecordNode.setProperty(AuditRecord.PROPERTY_OUTPUT, response.output)
}
} else {
if (response.result) {
auditRecordNode.setProperty(AuditRecord.PROPERTY_RESULT, response.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class DefaultGroovyConsoleService implements GroovyConsoleService {
} catch (MultipleCompilationErrorsException e) {
LOG.error("script compilation error", e)

response = RunScriptResponse.fromException(scriptContent, e)
response = RunScriptResponse.fromException(scriptContent, stream.toString(CharEncoding.UTF_8), e)
} catch (Throwable t) {
LOG.error("error running script", t)

response = RunScriptResponse.fromException(scriptContent, t)
response = RunScriptResponse.fromException(scriptContent, stream.toString(CharEncoding.UTF_8), t)

auditAndNotify(session, response)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ class EmailNotificationService implements NotificationService {
]

if (response.exceptionStackTrace) {
binding.stackTrace = response.exceptionStackTrace
binding.putAll([
stackTrace: response.exceptionStackTrace,
output: response.output
])
} else {
binding.putAll([
result: response.result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class RunScriptResponse {
new RunScriptResponse(script, data, resultString, output, "", runningTime)
}

static RunScriptResponse fromException(String script, Throwable throwable) {
static RunScriptResponse fromException(String script, String output, Throwable throwable) {
def exceptionStackTrace = ExceptionUtils.getStackTrace(throwable)

new RunScriptResponse(script, "", "", "", exceptionStackTrace, "")
new RunScriptResponse(script, "", "", output, exceptionStackTrace, "")
}

static RunScriptResponse fromAuditRecordResource(Resource resource) {
Expand All @@ -38,14 +38,14 @@ class RunScriptResponse {
def script = properties.get(PROPERTY_SCRIPT, "")
def data = properties.get(PROPERTY_DATA, "")
def exceptionStackTrace = properties.get(PROPERTY_EXCEPTION_STACK_TRACE, "")
def output = properties.get(AuditRecord.PROPERTY_OUTPUT, "")

def response

if (exceptionStackTrace) {
response = new RunScriptResponse(script, data, "", "", exceptionStackTrace, "")
response = new RunScriptResponse(script, data, "", output, exceptionStackTrace, "")
} else {
def result = properties.get(AuditRecord.PROPERTY_RESULT, "")
def output = properties.get(AuditRecord.PROPERTY_OUTPUT, "")
def runningTime = properties.get(AuditRecord.PROPERTY_RUNNING_TIME, "")

response = new RunScriptResponse(script, data, result, output, "", runningTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ class DefaultAuditServiceSpec extends ProsperSpec {
def "create audit record for script with exception"() {
when:
def exception = new RuntimeException("")
def response = RunScriptResponse.fromException("script content", exception)
def response = RunScriptResponse.fromException("script content", "output", exception)
def auditRecord = auditService.createAuditRecord(session, response)

then:
assertNodeExists(auditRecord.path)

and:
auditRecord.script == "script content"
auditRecord.output == "output"
auditRecord.exceptionStackTrace == ExceptionUtils.getStackTrace(exception)
}

Expand Down