Catching errors from executables


#1

This is more of a question about how to do something in Javascript with an API that is executing Python.

I have a linter with a block of code like this:

        return helpers.exec(atom.config.get('linter-ansible-linting.ansibleLintExecutablePath'), args).then(output => {
          var toReturn = [];
          output.split(/\r?\n/).forEach(function (line) {
            const matches = regex.exec(line);
            if (matches != null) {
              toReturn.push({
                type: 'Warning',
                range: helpers.rangeFromLineNumber(activeEditor, Number.parseInt(matches[1] - 1)),
                text: matches[3],
                filePath: file
              });
            }
          });
          return toReturn;
        });

I sometimes will get a Python IOError thrown from ansible-lint and I can safely ignore these. I asked how to do this with the atom-linter API here at steelbrain/atom-linter#128. Based on the reply, I made the following adjustment:

        return helpers.exec(atom.config.get('linter-ansible-linting.ansibleLintExecutablePath'), args).then(output => {
          var toReturn = [];
          output.split(/\r?\n/).forEach(function (line) {
            const matches = regex.exec(line);
            if (matches != null) {
              toReturn.push({
                type: 'Warning',
                range: helpers.rangeFromLineNumber(activeEditor, Number.parseInt(matches[1] - 1)),
                text: matches[3],
                filePath: file
              });
            }
          });
          return toReturn;
        })
        .catch({});

This had no effect. How do I instruct the catch to only catch the Python IOError (unsure if specific error catching is possible in Javascript) and how do I instruct the catch to give the error a ‘free pass?’


#2

I figured it out. I was missing the error in the catch. Also it seems Javascript can only catch error in general and not anything specific like other languages.