about summary refs log tree commit diff
path: root/uploader
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-24 11:15:58 -0600
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-24 11:41:48 -0600
commit4fcfde8f5cb3e1a8eeae7c72df98e29806d6e5b5 (patch)
tree25d5c3121c535c27519e150d4e2be29168f52cd6 /uploader
parent13ded023cb642d377e71dcc0dbf88df69e90a000 (diff)
downloadgn-uploader-4fcfde8f5cb3e1a8eeae7c72df98e29806d6e5b5.tar.gz
Bugfix: Add check for type of object before accessing member.
Check that `r.files[0]` is actually defined and has a "file" member
before attempting to access it for processing.

Add better error messaging to help user recover from the error(s).
Diffstat (limited to 'uploader')
-rw-r--r--uploader/templates/phenotypes/add-phenotypes-raw-files.html29
1 files changed, 24 insertions, 5 deletions
diff --git a/uploader/templates/phenotypes/add-phenotypes-raw-files.html b/uploader/templates/phenotypes/add-phenotypes-raw-files.html
index e76657a..2a5fd51 100644
--- a/uploader/templates/phenotypes/add-phenotypes-raw-files.html
+++ b/uploader/templates/phenotypes/add-phenotypes-raw-files.html
@@ -753,6 +753,7 @@
   ].map((row) => {
       r = makeResumableObject(row[0], row[1], row[2], row[3]);
       r.preview_table = $("#" + row[3]);
+      r.data_file_type = row[3].slice("tbl-preview".length + 1);
       return r;
   }).filter((val) => {
       return Boolean(val);
@@ -769,17 +770,35 @@
       // TODO: Verify that files are not duplicated
       var filenames = [];
       var nondupfiles = [];
+      var missing = [];
       resumables.forEach((r) => {
-          var fname = r.files[0].file.name;
-          filenames.push(fname);
-          if(!nondupfiles.includes(fname)) {
-              nondupfiles.push(fname);
+          var fileobj = r.files[0];
+          if(typeof fileobj !== "undefined" && Object.hasOwn(fileobj, "file")) {
+              var fname = fileobj.file.name;
+              filenames.push(fname);
+              if(!nondupfiles.includes(fname)) {
+                  nondupfiles.push(fname);
+              }
+          } else {
+              missing.push(r.data_file_type);
           }
       });
 
       // Check that all files were provided
       if(resumables.length !== filenames.length) {
-          window.alert("You MUST provide all the files requested.");
+          var _missingmap = {
+              "pheno-desc": "Phenotype descriptions",
+              "pheno-data": "Phenotype data",
+              "pheno-se": "Phenotype standard-errors",
+              "pheno-n": "Phenotype sample counts"
+          }
+          window.alert(
+              "You MUST provide all the requested files. Expected " +
+                  String(resumables.length) + " files but received " +
+                  String(filenames.length) + ".\r\n" +
+                  "Missing files:\r\n\t- " + missing.map((item) => {
+                      return _missingmap[item];
+                  }).join("\r\n\t- "));
           event.target.removeAttribute("disabled");
           return false;
       }