Skip to content

Commit 56432d4

Browse files
tomgreenfieldtaylortom
authored andcommitted
Pipe Grunt errors to front end
1 parent 0ec7583 commit 56432d4

4 files changed

Lines changed: 63 additions & 41 deletions

File tree

frontend/src/modules/editor/global/views/editorView.js

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,30 @@ define(function(require) {
9595
$('.editor-common-sidebar-previewing').removeClass('display-none');
9696

9797
var url = '/api/output/'+Origin.constants.outputPlugin+'/preview/'+this.currentCourseId+'?force='+(forceRebuild === true);
98-
$.get(url, _.bind(function(jqXHR, textStatus, errorThrown) {
99-
if(!jqXHR.success) {
98+
$.get(url, function(data, textStatus, jqXHR) {
99+
if (!data.success) {
100100
this.resetPreviewProgress();
101101
Origin.Notify.alert({
102102
type: 'error',
103-
text: Origin.l10n.t('app.errorgeneratingpreview')
103+
text: Origin.l10n.t('app.errorgeneratingpreview') +
104+
Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
104105
});
105106
previewWindow.close();
106107
return;
107108
}
108-
if (jqXHR.payload && typeof(jqXHR.payload.pollUrl) !== undefined && jqXHR.payload.pollUrl) {
109+
const pollUrl = data.payload && data.payload.pollUrl;
110+
if (pollUrl) {
109111
// Ping the remote URL to check if the job has been completed
110-
this.updatePreviewProgress(jqXHR.payload.pollUrl, previewWindow);
112+
this.updatePreviewProgress(pollUrl, previewWindow);
111113
return;
112114
}
113115
this.updateCoursePreview(previewWindow);
114116
this.resetPreviewProgress();
115-
}, this)).fail(_.bind(function(jqXHR, textStatus, errorThrown) {
117+
}.bind(this)).fail(function(jqXHR, textStatus, errorThrown) {
116118
this.resetPreviewProgress();
117119
Origin.Notify.alert({ type: 'error', text: Origin.l10n.t('app.errorgeneric') });
118120
previewWindow.close();
119-
}, this));
121+
}.bind(this));
120122
},
121123

122124
exportProject: function(error) {
@@ -134,30 +136,28 @@ define(function(require) {
134136

135137
var self = this;
136138
$.ajax({
137-
url: '/export/' + tenantId + '/' + courseId,
138-
success: function(data, textStatus, jqXHR) {
139-
self.showExportAnimation(false, $btn);
140-
self.exporting = false;
141-
142-
// get the zip
143-
var form = document.createElement('form');
144-
self.$el.append(form);
145-
form.setAttribute('action', '/export/' + tenantId + '/' + courseId + '/download.zip');
146-
form.submit();
147-
},
148-
error: function(jqXHR, textStatus, errorThrown) {
149-
var messageText = errorThrown;
150-
if(jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.message) messageText += ':<br/>' + jqXHR.responseJSON.message;
151-
152-
self.showExportAnimation(false, $btn);
153-
self.exporting = false;
154-
155-
Origin.Notify.alert({
156-
type: 'error',
157-
title: Origin.l10n.t('app.exporterrortitle'),
158-
text: messageText
159-
});
160-
}
139+
url: '/export/' + tenantId + '/' + courseId,
140+
success: function(data, textStatus, jqXHR) {
141+
self.showExportAnimation(false, $btn);
142+
self.exporting = false;
143+
144+
// get the zip
145+
var form = document.createElement('form');
146+
self.$el.append(form);
147+
form.setAttribute('action', '/export/' + tenantId + '/' + courseId + '/download.zip');
148+
form.submit();
149+
},
150+
error: function(jqXHR, textStatus, errorThrown) {
151+
self.showExportAnimation(false, $btn);
152+
self.exporting = false;
153+
154+
Origin.Notify.alert({
155+
type: 'error',
156+
title: Origin.l10n.t('app.exporterrortitle'),
157+
text: Origin.l10n.t('app.errorgeneric') +
158+
Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
159+
});
160+
}
161161
});
162162
},
163163

@@ -179,28 +179,32 @@ define(function(require) {
179179
$('.editor-common-sidebar-downloading').removeClass('display-none');
180180

181181
var url = '/api/output/' + Origin.constants.outputPlugin + '/publish/' + this.currentCourseId;
182-
$.get(url, _.bind(function(jqXHR, textStatus, errorThrown) {
183-
184-
if (!jqXHR.success) {
185-
Origin.Notify.alert({ type: 'error', text: Origin.l10n.t('app.errorgeneric') });
182+
$.get(url, function(data, textStatus, jqXHR) {
183+
if (!data.success) {
184+
Origin.Notify.alert({
185+
type: 'error',
186+
text: Origin.l10n.t('app.errorgeneric') +
187+
Origin.l10n.t('app.debuginfo', { message: jqXHR.responseJSON.message })
188+
});
186189
this.resetDownloadProgress();
187190
return;
188191
}
189-
if (jqXHR.payload && typeof(jqXHR.payload.pollUrl) !== undefined && jqXHR.payload.pollUrl) {
192+
const pollUrl = data.payload && data.payload.pollUrl;
193+
if (pollUrl) {
190194
// Ping the remote URL to check if the job has been completed
191-
this.updateDownloadProgress(jqXHR.payload.pollUrl);
195+
this.updateDownloadProgress(pollUrl);
192196
return;
193197
}
194198
this.resetDownloadProgress();
195199

196200
var $downloadForm = $('#downloadForm');
197-
$downloadForm.attr('action', '/download/' + Origin.sessionModel.get('tenantId') + '/' + Origin.editor.data.course.get('_id') + '/' + jqXHR.payload.zipName + '/download.zip');
201+
$downloadForm.attr('action', '/download/' + Origin.sessionModel.get('tenantId') + '/' + Origin.editor.data.course.get('_id') + '/' + data.payload.zipName + '/download.zip');
198202
$downloadForm.submit();
199203

200-
}, this)).fail(_.bind(function (jqXHR, textStatus, errorThrown) {
204+
}.bind(this)).fail(function(jqXHR, textStatus, errorThrown) {
201205
this.resetDownloadProgress();
202206
Origin.Notify.alert({ type: 'error', text: Origin.l10n.t('app.errorgeneric') });
203-
}, this));
207+
}.bind(this));
204208
},
205209

206210
updatePreviewProgress: function(url, previewWindow) {

frontend/src/modules/notify/plugins/alert/less/alert.less

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
.sweet-alert {
66
max-height: 91%;
77
overflow-y: auto;
8-
8+
details {
9+
display: block;
10+
margin-top: 20px;
11+
}
12+
textarea {
13+
font-family: monospace;
14+
}
915
button {
1016
min-width: 100px;
1117
margin: 10px 5px 20px 5px;

plugins/output/adapt/publish.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ function publishCourse(courseId, mode, request, response, next) {
3636

3737
var customPluginName = user._id;
3838

39+
const getGruntFatalError = stdout => {
40+
const indexStart = stdout.indexOf('\nFatal error: ');
41+
42+
if (indexStart === -1) return;
43+
44+
const indexEnd = stdout.indexOf('\n\nExecution Time');
45+
46+
return stdout.substring(indexStart, indexEnd !== -1 ? indexEnd : stdout.length);
47+
}
48+
3949
async.series([
4050
// get an object with all the course data
4151
function(callback) {
@@ -167,6 +177,7 @@ function publishCourse(courseId, mode, request, response, next) {
167177
if (error !== null) {
168178
logger.log('error', 'exec error: ' + error);
169179
logger.log('error', 'stdout error: ' + stdout);
180+
error.message += getGruntFatalError(stdout) || '';
170181
resultObject.success = true;
171182
return callback(error, 'Error building framework');
172183
}

routes/lang/en-application.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
"app.confirmdefaulttitle": "Are you sure?",
266266
"app.confirmdefaultyes": "Yes, I'm sure",
267267
"app.confirmwait": "Wait",
268+
"app.debuginfo": "<details><summary>Debug information</summary><textarea readonly rows='5'>%{message}</textarea></details>",
268269
"app.errorsessionexpired": "Your session has expired, click OK to log on again",
269270
"app.errorassetupdate": "Something went wrong while updating the asset.<br/>Please try again.",
270271
"app.errordeleteasset": "Couldn't delete this asset, %{message}",

0 commit comments

Comments
 (0)