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

0.75-rc.3: autolink should handle failures in rnc/cli config #45307

Closed
mfazekas opened this issue Jul 6, 2024 · 2 comments
Closed

0.75-rc.3: autolink should handle failures in rnc/cli config #45307

mfazekas opened this issue Jul 6, 2024 · 2 comments
Labels
Resolution: PR Submitted A pull request with a fix has been provided. Tool: Gradle Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@mfazekas
Copy link
Contributor

mfazekas commented Jul 6, 2024

Description

My yarn installation went wrong for some reason and executable permission was missing from rn-cli. Now it's fair that build failed, but it was failing in a cryptic way. Especially since the command mentioned in error message - react-native config was working fine.

Execution failed for task ':app:generateAutolinkingPackageList'.
> RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.

What's wasn't working and was invoked by gradle is npx @react-native-community/cli config

npx @react-native-community/cli config
sh: /private/tmp/TestAL/rn-075-autolink/ReproducerApp/node_modules/.bin/rnc-cli: Permission denied

Also the failure of the commend itself is not printed to grade and an empty autolink.json got created

ls -al build/generated/autolinking/autolinking.json
-rw-r--r--@ 1 boga  wheel  0 Jul  6 13:45 build/generated/autolinking/autolinking.json

Code should be logging failure of command and remove output file in such case.

if (lockFilesChanged || outputFile.exists().not() || outputFile.length() != 0L) {
ProcessBuilder(command)
.directory(workingDirectory)
.redirectOutput(ProcessBuilder.Redirect.to(outputFile))
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor(5, TimeUnit.MINUTES)
}

Something simple could be added to then end:

      val process = ProcessBuilder(command)
          .directory(workingDirectory)
          .redirectOutput(ProcessBuilder.Redirect.to(outputFile))
          .redirectError(ProcessBuilder.Redirect.INHERIT)
          .start()
      val finished = process
          .waitFor(5, TimeUnit.MINUTES)
      if (!finished) {
        Logging.getLogger("ReactSettingsExtension").error("Process ${command} exited with error code ${process.exitValue()}")
        throw GradleException("Process ${command} timed out")
      } else if (process.exitValue() != 0) {
        outputFile.delete()
        Logging.getLogger("ReactSettingsExtension").error("Process ${command} exited with error code ${process.exitValue()}")
        throw GradleException("Process ${command} exited with error code ${process.exitValue()}")
      }

Steps to reproduce

git clone https://github.com/mfazekas/rn-075-autolink
cd ReproducerApp
yarn install
chmod -x node_modules/.bin/rnc-cli 
cd android
./gradlew assembleDebug

React Native Version

0.75.0-rc.3

Affected Platforms

Runtime - Android, Build - MacOS

Areas

Codegen

Output of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (12) arm64 Apple M2 Max
  Memory: 66.97 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v18.20.2/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v18.20.2/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.2
    path: /Users/boga/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 20.0.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.8
    path: /Users/boga/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false


### Stacktrace or Logs

```text
Execution failed for task ':app:generateAutolinkingPackageList'.
> RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.

android % npx react-native config
{
"root": "/private/tmp/TestAL/rn-075-autolink/ReproducerApp",
"reactNativePath": "/private/tmp/TestAL/rn-075-autolink/ReproducerApp/node_modules/react-native",
"reactNativeVersion": "0.75",
...
}

Reproducer

https://github.com/mfazekas/rn-075-autolink

Screenshots and Videos

No response

@mfazekas mfazekas added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jul 6, 2024
@mfazekas mfazekas changed the title 0.75-rc.3: auto link should handle failures 0.75-rc.3: autolink should handle failures in rnc/cli config Jul 6, 2024
@cortinico
Copy link
Contributor

Something simple could be added to then end:

Sounds great to me 👍 Could you send this as a PR @mfazekas and ping me there?

@mfazekas
Copy link
Contributor Author

mfazekas commented Jul 8, 2024

@cortinico PR #45333 added

@cortinico cortinico added the Resolution: PR Submitted A pull request with a fix has been provided. label Jul 9, 2024
blakef pushed a commit that referenced this issue Jul 15, 2024
…n zero exit code (#45333)

Summary:
Fixes: #45307

## Changelog:

[Android] [Fixed] - if `npx react-native-community/cli config` fails or timeouts proper error is shown and built is aborted, instead of leaving and empty autolinking.json

During build `npx react-native-community/cli config` is generated into autolinking.json. When command fails, we should error and should not leave and empty `autolinking.json`

Pull Request resolved: #45333

Test Plan:
Output of the reproducer in #45307 looks like this:

```log
android % ./gradlew assembleDebug
Starting a Gradle Daemon (subsequent builds will be faster)
ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config  exited with error code: 126

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config  exited with error code: 126

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s
8 actionable tasks: 4 executed, 4 up-to-date
```

Output if you modify the package.json to be invalid looks like this:

```log
android % ./gradlew assembleDebug
ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config  exited with error code: 1
JSONError: JSON Error in /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/package.json:

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

Unexpected token "S" (0x53) in JSON at position 1019 while parsing near "...ode\": \">=18\"\n  },\n  SOMETHING_NON_JSON\n ..."

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

    at parseJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/parse-json/index.js:29:21)
    at loadJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/loaders.js:48:16)
    at #loadConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:116:36)
    at #loadConfigFileWithImports (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:87:54)
    at #readConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:84:82)
    at search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:50:63)
    at emplace (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/util.js:36:20)
    at ExplorerSync.search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:78:42)
    at getUserDefinedOptionsFromMetaConfig (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:32:37)
    at mergeOptionsBase (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:60:31)

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config  exited with error code: 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
8 actionable tasks: 4 executed, 4 up-to-date
```

Reviewed By: cipolleschi

Differential Revision: D59582430

Pulled By: cortinico

fbshipit-source-id: bedb9563175cc5c46f5af80cf309769e56b803cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: PR Submitted A pull request with a fix has been provided. Tool: Gradle Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
2 participants