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

No useful error when attempting to preview course with empty children #2067

Closed
tomgreenfield opened this issue Sep 6, 2018 · 0 comments
Closed
Assignees
Labels
S: merged Completed, reviewed, and merged issues T: bug
Milestone

Comments

@tomgreenfield
Copy link
Contributor

tomgreenfield commented Sep 6, 2018

On develop branch, attempt to preview a course with no content objects, or a block with no components etc.

Erroring function:

OutputPlugin.prototype.sanitizeCourseJSON = function(mode, json, next) {
var self = this;
try {
var outputJson = json;
var courseJson = outputJson['course'][0];
var configJson = outputJson['config'][0];
var contentObjectJson = outputJson['contentobject'];
var blockJson = outputJson['block'];
var componentJson = outputJson['component'];
var courseId = courseJson._id;
// The Adapt Framework expects the 'type' and '_id'
// attributes of the course to be set to 'course'
courseJson._type = 'course';
courseJson._id = 'course';
courseJson._latestTrackingId = blockJson.length;
// Replace any reference to the original course _id value in contentObjects JSON
for (var i = 0; i < contentObjectJson.length; i++) {
if (contentObjectJson[i]._parentId.toString() == courseId) {
contentObjectJson[i]._parentId = 'course';
}
}
// Add a _trackingId value to every block
for (var i = 0; i < blockJson.length; i++) {
blockJson[i]._trackingId = (i + 1);
}
// The 'properties' property of a component should not be included as an
// attribute in the output, but all its children should
for (var i = 0; i < componentJson.length; i++) {
if (componentJson[i].hasOwnProperty('properties')) {
for(var key in componentJson[i].properties){
if (componentJson[i].properties.hasOwnProperty(key)){
componentJson[i][key] = componentJson[i].properties[key];
}
}
// Remove the 'properties' property
delete componentJson[i].properties;
}
}
async.waterfall([
function(callback) {
if (mode === Constants.Modes.export) {
return callback();
}
self.generateIncludesForConfig(configJson, function(error, includes) {
if (error) {
return callback(error);
}
configJson.build = { includes: includes };
callback();
});
}
], function(error) {
if (error) {
logger.log(error);
return next(error);
}
// Store the sanitized JSON
Object.assign(outputJson, {
course: courseJson,
config: configJson,
contentobject: contentObjectJson,
component: componentJson
});
next(null, outputJson);
});
} catch(err) {
return next(err);
}
};

Frontend output:

Backend output:

info: [06 Sep 2018 12:25:38 +01:00] Retrieving JSON
error: [06 Sep 2018 12:27:27 +01:00] TypeError: Cannot read property 'length' of undefined
@taylortom taylortom added this to the 0.5.1 milestone Sep 17, 2018
@lc-thomasberger lc-thomasberger self-assigned this Sep 24, 2018
@lc-thomasberger lc-thomasberger added T: bug S: in-progress Issues currently being worked on - leave these be! labels Sep 24, 2018
@lc-thomasberger lc-thomasberger added S: awaiting-review Completed issues waiting on reviews and removed S: in-progress Issues currently being worked on - leave these be! labels Sep 24, 2018
@lc-thomasberger lc-thomasberger added S: merged Completed, reviewed, and merged issues and removed S: awaiting-review Completed issues waiting on reviews labels Oct 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: merged Completed, reviewed, and merged issues T: bug
Projects
None yet
Development

No branches or pull requests

4 participants