@@ -887,91 +887,91 @@ export default class Parsons extends RunestoneBase {
887887 }
888888 // Based on the data, load
889889 async loadData ( data ) {
890-
891- if ( this . options . scaffolding === true ) {
892- var sourceHash = data . source ;
893- if ( sourceHash == undefined ) {
894- // maintain backwards compatibility
895- sourceHash = data . trash ;
896- }
897- var answerHash = data . answer ;
898- var adaptiveHash = data . adaptive ;
899- var options ;
900- if ( adaptiveHash == undefined ) {
901- options = { } ;
902- } else {
903- options = this . optionsFromHash ( adaptiveHash ) ;
904- }
905- if ( options . noindent !== undefined ) {
906- this . noindent = true ;
907- }
908- if ( options . checkCount !== undefined ) {
909- this . checkCount = options . checkCount ;
910- }
911- if ( options . hasSolved !== undefined ) {
912- this . hasSolved = options . hasSolved ;
913- }
914- await this . initializeAreas ( this . blocksFromSource ( ) , this . settledBlocksFromSource ( ) , options ) ;
915- if ( this . needsReinitialization !== true ) {
916- this . initializeInteractivity ( ) ;
917- if ( this . isTimed && ! this . assessmentTaken ) {
918- this . resetView ( ) ;
890+ // guard against any failure to load/adapt problem
891+ try {
892+ if ( this . options . scaffolding === true ) {
893+ var sourceHash = data . source ;
894+ if ( sourceHash == undefined ) {
895+ // maintain backwards compatibility
896+ sourceHash = data . trash ;
897+ }
898+ var answerHash = data . answer ;
899+ var adaptiveHash = data . adaptive ;
900+ var options ;
901+ if ( adaptiveHash == undefined ) {
902+ options = { } ;
903+ } else {
904+ options = this . optionsFromHash ( adaptiveHash ) ;
919905 }
920- }
921- } else {
922- var sourceHash = data . source ;
923- if ( sourceHash == undefined ) {
924- // maintain backwards compatibility
925- sourceHash = data . trash ;
926- }
927- var answerHash = data . answer ;
928- var adaptiveHash = data . adaptive ;
929- var options ;
930- if ( adaptiveHash == undefined ) {
931- options = { } ;
932- } else {
933- options = this . optionsFromHash ( adaptiveHash ) ;
934- }
935- if ( options . noindent !== undefined ) {
936- this . noindent = true ;
937- }
938- if ( options . checkCount !== undefined ) {
939- this . checkCount = options . checkCount ;
940- }
941- if ( options . hasSolved !== undefined ) {
942- this . hasSolved = options . hasSolved ;
943- }
944- if (
945- sourceHash == undefined ||
946- answerHash == undefined ||
947- answerHash . length == 1
948- ) {
949- await this . initializeAreas ( this . blocksFromSource ( ) , [ ] , options ) ;
906+ if ( options . noindent !== undefined ) {
907+ this . noindent = true ;
908+ }
909+ if ( options . checkCount !== undefined ) {
910+ this . checkCount = options . checkCount ;
911+ }
912+ if ( options . hasSolved !== undefined ) {
913+ this . hasSolved = options . hasSolved ;
914+ }
915+ await this . initializeAreas ( this . blocksFromSource ( ) , this . settledBlocksFromSource ( ) , options ) ;
950916 } else {
951- this . initializeAreas (
952- this . blocksFromHash ( sourceHash ) ,
953- this . blocksFromHash ( answerHash ) ,
954- options
955- ) ;
956- this . grade = this . grader . grade ( ) ;
957- if ( this . grade == "correct" ) {
958- this . correct = true ;
959- } else if ( this . answerLines ( ) . length == 0 ) {
960- this . correct = null ;
917+ var sourceHash = data . source ;
918+ if ( sourceHash == undefined ) {
919+ // maintain backwards compatibility
920+ sourceHash = data . trash ;
921+ }
922+ var answerHash = data . answer ;
923+ var adaptiveHash = data . adaptive ;
924+ var options ;
925+ if ( adaptiveHash == undefined ) {
926+ options = { } ;
961927 } else {
962- this . correct = false ;
928+ options = this . optionsFromHash ( adaptiveHash ) ;
963929 }
964- }
965- // Start the interface
966- if ( this . needsReinitialization !== true ) {
967- this . initializeInteractivity ( ) ;
968- // This is a bit of a hack to get the blocks to be in the right place
969- // when the page loads. It is needed because the blocks are not
970- // visible when the page loads, so the size is off. This forces
971- // a realignment.
972- if ( this . isTimed && ! this . assessmentTaken ) {
973- this . resetView ( ) ;
930+ if ( options . noindent !== undefined ) {
931+ this . noindent = true ;
932+ }
933+ if ( options . checkCount !== undefined ) {
934+ this . checkCount = options . checkCount ;
935+ }
936+ if ( options . hasSolved !== undefined ) {
937+ this . hasSolved = options . hasSolved ;
974938 }
939+ if (
940+ sourceHash == undefined ||
941+ answerHash == undefined ||
942+ answerHash . length == 1
943+ ) {
944+ await this . initializeAreas ( this . blocksFromSource ( ) , [ ] , options ) ;
945+ } else {
946+ this . initializeAreas (
947+ this . blocksFromHash ( sourceHash ) ,
948+ this . blocksFromHash ( answerHash ) ,
949+ options
950+ ) ;
951+ this . grade = this . grader . grade ( ) ;
952+ if ( this . grade == "correct" ) {
953+ this . correct = true ;
954+ } else if ( this . answerLines ( ) . length == 0 ) {
955+ this . correct = null ;
956+ } else {
957+ this . correct = false ;
958+ }
959+ }
960+ }
961+ } catch ( err ) {
962+ // if anything goes wrong, just initialize based on problem source
963+ await this . initializeAreas ( this . blocksFromSource ( ) , [ ] , options ) ;
964+ console . log ( `Error restoring answer for student ${ data . sid } in ${ data . div_id } . Defaulting to original state.` )
965+ }
966+ // Start the interface
967+ if ( this . needsReinitialization !== true ) {
968+ this . initializeInteractivity ( ) ;
969+ // This is a bit of a hack to get the blocks to be in the right place
970+ // when the page loads. It is needed because the blocks are not
971+ // visible when the page loads, so the size is off. This forces
972+ // a realignment.
973+ if ( this . isTimed && ! this . assessmentTaken ) {
974+ this . resetView ( ) ;
975975 }
976976 }
977977 }
0 commit comments