Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to catch an exception #48

Open
JesusLopezCh opened this issue Mar 13, 2019 · 2 comments
Open

Not able to catch an exception #48

JesusLopezCh opened this issue Mar 13, 2019 · 2 comments

Comments

@JesusLopezCh
Copy link

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");
            }

        });
@stevetarver
Copy link
Owner

@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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants