Skip to content

Commit 2d4eec5

Browse files
authored
fix: catch errors from malformed MIDI files on import (#6655)
* fix: catch errors from malformed MIDI files on import Signed-off-by: Ady0333 <adityashinde1525@gmail.com> * fix: make MIDI import error handling safer and improve logging --------- Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
1 parent d9cfeaa commit 2d4eec5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

js/activity.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8341,10 +8341,20 @@ class Activity {
83418341
};
83428342

83438343
midiReader.onload = e => {
8344-
const midi = new Midi(e.target.result);
8345-
8346-
console.debug(midi);
8347-
midiImportBlocks(midi);
8344+
try {
8345+
const midi = new Midi(e.target.result);
8346+
console.debug(midi);
8347+
midiImportBlocks(midi);
8348+
} catch (err) {
8349+
console.error("MIDI import failed:", err);
8350+
if (that && typeof that.errorMsg === "function") {
8351+
that.errorMsg(
8352+
_(
8353+
"Cannot load project from the file. Please check the file type."
8354+
)
8355+
);
8356+
}
8357+
}
83488358
};
83498359

83508360
const file = that.fileChooser.files[0];
@@ -8438,10 +8448,18 @@ class Activity {
84388448
}, 200);
84398449
};
84408450
midiReader.onload = e => {
8441-
const midi = new Midi(e.target.result);
8442-
8443-
console.debug(midi);
8444-
midiImportBlocks(midi);
8451+
try {
8452+
const midi = new Midi(e.target.result);
8453+
console.debug(midi);
8454+
midiImportBlocks(midi);
8455+
} catch (err) {
8456+
console.error("MIDI import failed:", err);
8457+
if (that && typeof that.errorMsg === "function") {
8458+
that.errorMsg(
8459+
_("Cannot load project from the file. Please check the file type.")
8460+
);
8461+
}
8462+
}
84458463
};
84468464

84478465
// Music Block Parser from abc to MB

0 commit comments

Comments
 (0)