formatjs / formatjs

The monorepo home to all of the FormatJS related libraries, most notably react-intl.

Home Page:https://formatjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cli-lib's `extract` function ignores `throws` setting for errors in `processFile`

TNick opened this issue · comments

https://github.com/formatjs/formatjs/blob/c063f7bc4530af7ec6c5b68000887a3f55948f6e/packages/cli-lib/src/extract.ts#L200C18

try {
  const source = await readFile(fn, 'utf8')
  return processFile(source, fn, opts)
} catch (e) {
  if (throws) {
    throw e
  } else {
    warn(String(e))
  }
}

In this code exceptions thrown in processFile will not be caught because processFile is an async function.

Is this the intention or is it a bug?

try {
  const source = await readFile(fn, 'utf8')
  return Promise.resolve(await processFile(source, fn, opts));
} catch (e) {
  if (throws) {
    throw e
  } else {
    warn(String(e))
  }
}