Skip to content

Commit b735822

Browse files
authored
Merge pull request #170 from smartin015/harden_rmfile
Harden rmfile
2 parents a33fe94 + 4451510 commit b735822

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

continuousprint/static/js/continuousprint_viewmodel.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ function CPViewModel(parameters) {
8383
let oldRemove = self.files.removeFile;
8484
let remove_cb = null;
8585
self.files.removeFile = function(data, evt) {
86-
for (let j of self.defaultQueue.jobs()) {
87-
for (let s of j.sets()) {
88-
if (s.path() === data.path) {
89-
remove_cb = () => oldRemove(data, evt);
90-
return self.showRemoveConfirmModal()
86+
try {
87+
for (let j of self.defaultQueue.jobs()) {
88+
for (let s of j.sets()) {
89+
if (s.path() === data.path) {
90+
remove_cb = () => oldRemove(data, evt);
91+
return self.showRemoveConfirmModal()
92+
}
9193
}
9294
}
93-
}
95+
} catch {} // Fail silently on error, and pass through
9496
return oldRemove(data, evt);
9597
};
9698
self.rmDialog = $("#cpq_removeConfirmDialog");

continuousprint/static/js/continuousprint_viewmodel.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ test('removeFile shows dialog', () => {
208208
expect(rmfile).not.toHaveBeenCalled();
209209
});
210210

211+
test('removeFile with exception fails gracefully', () => {
212+
let m = mocks();
213+
let rmfile = m[2].removeFile;
214+
let v = init(1, m);
215+
v.defaultQueue = null; // Can't call .jobs() on null queue
216+
let data = {path: 'asdf'};
217+
v.files.removeFile(data, null); // Raises exception
218+
expect(rmfile).toHaveBeenCalledWith(data, null); // But still gets forwarded through
219+
});
220+
211221
test('removeConfirm calls removeFile', () => {
212222
let m = mocks();
213223
let rmfile = m[2].removeFile;

0 commit comments

Comments
 (0)