react-native-community / react-native-community/cli

Tons of errors are ignored

Open
#2,852 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.9k
Forks
949
PR merge metrics
No merged PRs in 30d

Description

Hello. This bug is to keep track of a multitude of small issues where errors are silently ignored or misinterpreted. There are several pull requests fixing some of them already but this one does not appear to have a PR yet and is a great example. From isPackagerRunning.ts:

async function isPackagerRunning(
  packagerPort: string | number = process.env.RCT_METRO_PORT || '8081',
): Promise<
  | {
      status: 'running';
      root: string;
    }
  | 'not_running'
  | 'unrecognized'
> {
  try {
    const {data, headers} = await fetch(
      `http://localhost:${packagerPort}/status`,
    );

    try {
      if (data === 'packager-status:running') {
        return {
          status: 'running',
          root: headers.get('X-React-Native-Project-Root') ?? '',
        };
      }
    } catch (_error) {
      return 'unrecognized';
    }
    return 'unrecognized';
  } catch (_error) {
    return 'not_running';
  }
}

Two issues here had me chasing false starts with another bug:

  • Any error interpreting the data (e.g. data is undefined) is treated as undefined. This will likely be wrong so at minimum there should be a visible by default warning in this scenario
  • Any issue during this entire process that isn't explicitly handles is treated as not_running. Again this might be ok if the unrecognized error were visible, since that will not always be the correct thing to do

Bit of a side note with this snippet, there is a lot of unnecessary complexity that stems from the strange shape of this methods return type. We might want to make it something like

{status: 'running' | 'not_running' | 'unrecognized', root: string?} 

and/or use an enum for the status. This is just "bug prone" not itself a bug, and we would need to refractor this area anyway, so let me know if we feel like this should be its own bug or if we should ignore it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with isPackagerRunning.ts and trace each nested try/catch around the fetch, response data, and headers. Compare the reported undefined-data and unexpected-error cases with the intended running, not_running, and unrecognized outcomes. Done means errors are no longer silently ignored or misinterpreted, with the behavior made visible where the issue requires it.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.