quick-lint-js

Find bugs in JavaScript programs.

E0117: unexpected 'catch' without 'try'

try statements can have a catch clause. It is a syntax error to have a catch clause with no corresponding try statement:

async function readConfig(configFilePath) {
  try {
    let data = await fs.promises.readFile(
      configFilePath,
      "utf-8",
    );
    return parseConfig(data);
  };
  catch (error) {
    if (error.code === 'ENOENT') {
      return {};
    } else {
      throw error;
    }
  }
}

To fix this error, make sure the catch keyword immediately follows the } for a try block:

async function readConfig(configFilePath) {
  try {
    let data = await fs.promises.readFile(
      configFilePath,
      "utf-8",
    );
    return parseConfig(data);
  }
  catch (error) {
    if (error.code === 'ENOENT') {
      return {};
    } else {
      throw error;
    }
  }
}

Documentation for other errors