Skip to content

Commit 55f60cd

Browse files
committed
fix #1785 -- if you enable peer grading but don't have enough students you get an uncaught exception
diff --git a/src/packages/frontend/course/assignments/actions.ts b/src/packages/frontend/course/assignments/actions.ts index 4f635db..9b1ffaf 100644 --- a/src/packages/frontend/course/assignments/actions.ts +++ b/src/packages/frontend/course/assignments/actions.ts @@ -909,7 +909,12 @@ ${details} // in parallel, two will launch at about the same time and // the *condition* to know if it is done depends on the store, // which defers when it gets updated. Anyway, this line is critical: - this.update_peer_assignment(assignment_id); + try { + this.update_peer_assignment(assignment_id); + } catch (err) { + this.course_actions.set_error(`${short_desc} -- ${err}`); + return; + } await this.start_all_for_peer_grading(); // OK, now do the assignment... in parallel. await this.assignment_action_all_students( @@ -1037,7 +1042,15 @@ ${details} desc: `Copying peer grading to ${student_name}`, }); - const peer_map = this.update_peer_assignment(assignment_id); // synchronous + let peer_map; + try { + // synchronous, but could fail, e.g., not enough students + peer_map = this.update_peer_assignment(assignment_id); + } catch (err) { + this.course_actions.set_error(`peer copy to student: ${err}`); + finish(); + return; + } if (peer_map == null) { finish(); diff --git a/src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx b/src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx index 6e8b57d..7dcd4c3 100644 --- a/src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx +++ b/src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx @@ -19,7 +19,8 @@ import { useRedux, useTypedRedux, } from "@cocalc/frontend/app-framework"; -import { Loading, ActivityDisplay, ErrorDisplay } from "../../components"; +import { Loading, ActivityDisplay } from "../../components"; +import ShowError from "@cocalc/frontend/components/error"; import { AssignmentsMap, CourseSettingsRecord, @@ -73,20 +74,20 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo( const students: StudentsMap | undefined = useRedux(name, "students"); const assignments: AssignmentsMap | undefined = useRedux( name, - "assignments" + "assignments", ); const handouts: HandoutsMap | undefined = useRedux(name, "handouts"); const settings: CourseSettingsRecord | undefined = useRedux( name, - "settings" + "settings", ); const configuring_projects: boolean | undefined = useRedux( name, - "configuring_projects" + "configuring_projects", ); const reinviting_students: boolean | undefined = useRedux( name, - "reinviting_students" + "reinviting_students", ); const activity: Map<string, any> | undefined = useRedux(name, "activity"); const error: string | undefined = useRedux(name, "error"); @@ -188,12 +189,11 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo( } function render_error(): Rendered { - if (!error) return; return ( - <ErrorDisplay - banner={true} + <ShowError + style={{ margin: "15px" }} error={error} - onClose={() => { + setError={(error) => { const actions = redux.getActions(name) as CourseActions; if (actions != null) actions.set_error(""); }} @@ -213,7 +213,7 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo( {render_panel()} </div> ); - } + }, ); export function wrap(Panel) {
1 parent 5549b07 commit 55f60cd

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/packages/frontend/course/assignments/actions.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,12 @@ ${details}
909909
// in parallel, two will launch at about the same time and
910910
// the *condition* to know if it is done depends on the store,
911911
// which defers when it gets updated. Anyway, this line is critical:
912-
this.update_peer_assignment(assignment_id);
912+
try {
913+
this.update_peer_assignment(assignment_id);
914+
} catch (err) {
915+
this.course_actions.set_error(`${short_desc} -- ${err}`);
916+
return;
917+
}
913918
await this.start_all_for_peer_grading();
914919
// OK, now do the assignment... in parallel.
915920
await this.assignment_action_all_students(
@@ -1037,7 +1042,15 @@ ${details}
10371042
desc: `Copying peer grading to ${student_name}`,
10381043
});
10391044

1040-
const peer_map = this.update_peer_assignment(assignment_id); // synchronous
1045+
let peer_map;
1046+
try {
1047+
// synchronous, but could fail, e.g., not enough students
1048+
peer_map = this.update_peer_assignment(assignment_id);
1049+
} catch (err) {
1050+
this.course_actions.set_error(`peer copy to student: ${err}`);
1051+
finish();
1052+
return;
1053+
}
10411054

10421055
if (peer_map == null) {
10431056
finish();

src/packages/frontend/frame-editors/course-editor/course-panel-wrapper.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
useRedux,
2020
useTypedRedux,
2121
} from "@cocalc/frontend/app-framework";
22-
import { Loading, ActivityDisplay, ErrorDisplay } from "../../components";
22+
import { Loading, ActivityDisplay } from "../../components";
23+
import ShowError from "@cocalc/frontend/components/error";
2324
import {
2425
AssignmentsMap,
2526
CourseSettingsRecord,
@@ -73,20 +74,20 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo(
7374
const students: StudentsMap | undefined = useRedux(name, "students");
7475
const assignments: AssignmentsMap | undefined = useRedux(
7576
name,
76-
"assignments"
77+
"assignments",
7778
);
7879
const handouts: HandoutsMap | undefined = useRedux(name, "handouts");
7980
const settings: CourseSettingsRecord | undefined = useRedux(
8081
name,
81-
"settings"
82+
"settings",
8283
);
8384
const configuring_projects: boolean | undefined = useRedux(
8485
name,
85-
"configuring_projects"
86+
"configuring_projects",
8687
);
8788
const reinviting_students: boolean | undefined = useRedux(
8889
name,
89-
"reinviting_students"
90+
"reinviting_students",
9091
);
9192
const activity: Map<string, any> | undefined = useRedux(name, "activity");
9293
const error: string | undefined = useRedux(name, "error");
@@ -188,12 +189,11 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo(
188189
}
189190

190191
function render_error(): Rendered {
191-
if (!error) return;
192192
return (
193-
<ErrorDisplay
194-
banner={true}
193+
<ShowError
194+
style={{ margin: "15px" }}
195195
error={error}
196-
onClose={() => {
196+
setError={(error) => {
197197
const actions = redux.getActions(name) as CourseActions;
198198
if (actions != null) actions.set_error("");
199199
}}
@@ -213,7 +213,7 @@ const CoursePanelWrapper: React.FC<FrameProps> = React.memo(
213213
{render_panel()}
214214
</div>
215215
);
216-
}
216+
},
217217
);
218218

219219
export function wrap(Panel) {

0 commit comments

Comments
 (0)