excel-as-json icon indicating copy to clipboard operation
excel-as-json copied to clipboard

Not able to catch an exception

Open JesusLopezCh opened this issue 5 years ago • 2 comments

Our application generates a XLS report, but right now we have an issue where it is generating a corrupted xls, but I realized that an error is not caught trying to read this corrupted xls, I try debugging and identified specifically in the "return excel()" function it doesn't enters, not sure how to provide my xls as an example.

  processFile = function(src, dst, options = _DEFAULT_OPTIONS, callback = void 0) {
    options = _validateOptions(options);
    if (!callback) {
      callback = function(err, data) {};
    }
    // NOTE: 'excel' does not properly bubble file not found and prints
    //       an ugly error we can't trap, so look for this common error first
    if (!fs.existsSync(src)) {
      return callback(`Cannot find src file ${src}`);
    } else {
      return excel(src, options.sheet, function(err, data) {
============>>> CODE NEVER REACHES THIS PART <<<==================
        var result;
        if (err) {
          return callback(`Error reading ${src}: ${err}`);
        } else {
          result = convert(data, options);
          if (dst) {
            return write(result, dst, function(err) {
              if (err) {
                return callback(err);
              } else {
                return callback(void 0, result);
              }
            });
          } else {
            return callback(void 0, result);
          }
        }
      });
============>>> CODE NEVER REACHES THIS PART <<<==================
    }
  };

So , when I try this, it doesn't even prints the first console.log();

        convertExcel(filename, 'row.json', options, (err, data) => {

            console.log("Starts")

            if (err) {
                console.log("err " + err);
                console.log("data " + data)
            }
            else {
                console.log("else");
            }

        });

JesusLopezCh avatar Mar 13 '19 22:03 JesusLopezCh

@JesusLopezCh , I have noticed this in the past as well. The dependent package, "excel", does not report errors on some failure to load a file - as confirmed by your test. I encourage you to create an issue with that project - you have enough information in your work above to create a minimal reproducible test case.

I'm sure you have noticed that you can work around this limit by raising an error if no content is produced. You could even replicate the processFile code in your project to specifically identify when excel produces no data for you to work on.

I appreciate your debugging efforts and quality of your issue report.

stevetarver avatar Mar 16 '19 19:03 stevetarver

Note: leaving this issue open to track progress or mitigation. Perhaps throw our own exception when excel does not produce data.

stevetarver avatar Mar 16 '19 19:03 stevetarver