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

Generating files on github actions yields Null check operator used on a null value error (works locally) #3125

Closed
moseskarunia opened this issue Jun 11, 2021 · 13 comments

Comments

@moseskarunia
Copy link

Script which yields the error

flutter pub run build_runner build --delete-conflicting-outputs

Confusingly the error only happened on github action CI and not local, even though I use the exact same script on both local and remote.

Error Log

Log
Run flutter pub run build_runner build --delete-conflicting-outputs
flutter pub run build_runner build --delete-conflicting-outputs
shell: /usr/bin/bash -e {0}
env:
  FLUTTER_ROOT: /opt/hostedtoolcache/flutter/2.0.6-stable/x64
  PUB_CACHE: /opt/hostedtoolcache/flutter/2.0.6-stable/x64/.pub-cache

Unhandled exception:
Null check operator used on a null value
#0      PackageGraph.forPath.<anonymous closure> (package:build_runner_core/src/package_graph/package_graph.dart:106:72)
#1      MappedListIterable.elementAt (dart:_internal/iterable.dart:411:31)
#2      ListIterator.moveNext (dart:_internal/iterable.dart:340:26)
#3      List.addAll (dart:core-patch/growable_array.dart:308:13)
#4      PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:106:12)
<asynchronous suspension>
#5      main (file:///opt/hostedtoolcache/flutter/2.0.6-stable/x64/.pub-cache/hosted/pub.dartlang.org/build_runner-2.0.4/bin/build_runner.dart:27:30)
<asynchronous suspension>
pub finished with exit code 255
Error: Process completed with exit code 255.

Github action

Github action.yaml
name: horeekaa-core

on:
  push:
    branches: [master]
    paths:
      - ".github/workflows/horeekaa-core.yaml"
      - "horeekaa_core/**"
  pull_request:
    branches: [master, epic-**, init-**-epic-**]
    paths:
      - ".github/workflows/horeekaa-core.yaml"
      - "horeekaa_core/**"

jobs:
  build:
    defaults:
      run:
        working-directory: horeekaa_core
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: subosito/flutter-action@v1
        with:
          flutter-version: '2.0.6'
      - name: Copy Assets
        run: cp -R ../assets assets
      - name: Install dependencies
        run: flutter pub get
      - name: Generate files
        run: flutter pub run build_runner build --delete-conflicting-outputs
      - name: Format
        run: flutter format --set-exit-if-changed lib test
      - name: Analyze project source
        run: flutter analyze lib test
      - name: Test
        run: flutter test --coverage
      - name: Activate remove_from_coverage
        run: pub global activate remove_from_coverage
      - name: Remove autogenerated codes from coverage report
        run: pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.config.dart$' && pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$' && pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$'
      - name: Report code coverage
        uses: zgosalvez/[email protected]
        with:
          working-directory: horeekaa_core
          coverage-files: horeekaa_core/coverage/lcov.info
          minimum-coverage: 95
          artifact-name: code-coverage-report
          github-token: ${{ secrets.GITHUB_TOKEN }}

To give some perspective, here's my folder structure:

Folder structure Screen Shot 2021-06-11 at 18 45 28

My pubspec.yaml

pubspec.yaml
name: horeekaa_core
description: A flutter library containing core horeekaa codes
version: 0.16.0

environment:
  sdk: '>=2.12.0 <3.0.0'
  flutter: 2.0.6

dependencies:
  flutter:
    sdk: flutter
  built_value: 8.0.6
  clock: 1.1.0
  copy_with_extension: 2.0.0-nullsafety.1
  cornerstone: 2.0.0-nullsafety.10
  dartz: 0.10.0-nullsafety.1
  dotted_border: 2.0.0-nullsafety.0
  equatable: 2.0.0
  firebase_auth: 1.0.2
  firebase_core: 1.3.0
  firebase_crashlytics: 2.0.0
  firebase_dynamic_links: 2.0.0-dev.1
  firebase_messaging: 10.0.2
  flutter_bloc: 7.0.0
  flutter_cafe: 0.0.2-dev.5
  flutter_i18n: 0.22.3
  freezed: 0.14.2
  get_it: 7.1.3
  google_fonts: 2.0.0
  google_sign_in: 5.0.1
  graphql_flutter: 5.0.0-nullsafety.2
  hive: 2.0.0
  hive_flutter: 1.0.0
  image_picker: 0.7.4
  injectable: 1.4.0
  intl: 0.17.0
  json_annotation: 4.0.1
  linked_scroll_controller: 0.2.0-nullsafety.0
  material_design_icons_flutter: 5.0.5955-rc.1
  meta: 1.3.0
  package_info: 2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  bloc_test: 8.0.0
  build_runner: 2.0.4
  flutter_launcher_icons: 0.9.0
  injectable_generator: 1.4.0
  json_serializable: 4.1.2
  mocktail: 0.1.0

flutter: null
@moseskarunia moseskarunia changed the title Generating files on github actions yields Null check operator used on a null value error, works locally Generating files on github actions yields Null check operator used on a null value error (works locally) Jun 11, 2021
@kuhnroyal
Copy link

You probably don't have your pubspec.lock checked int Git or you run flutter pub upgrade in CI which leads to different dependencies during the CI run.

@moseskarunia
Copy link
Author

You probably don't have your pubspec.lock checked int Git or you run flutter pub upgrade in CI which leads to different dependencies during the CI run.

Hi thanks for the reply. I never checked in my pubspec.lock file and I didn't run flutter pub upgrade. See my github ci file for more info

@kuhnroyal
Copy link

I never checked in my pubspec.lock file

That is what I am saying. That can lead to CI using newer dependencies than you are using locally.
Try running flutter pub upgrade locally and then flutter pub run build_runner build.

@moseskarunia
Copy link
Author

moseskarunia commented Jun 11, 2021

I never checked in my pubspec.lock file

That is what I am saying. That can lead to CI using newer dependencies than you are using locally.
Try running flutter pub upgrade locally and then flutter pub run build_runner build.

Thank you. I'm able to reproduce it locally. This is quite strange because my pubspec.yaml use an exact versioning. For example clock: 1.1.0 instead of clock: ^1.1.0 or clock: '>=1.1.0 <2.0.0'.

Do you know what caused the error? Thanks

@kuhnroyal
Copy link

No, one of the transitive dependencies causes this since they are not locked. You should diff you pubspec.lock before and after the upgrade.
For this reason it is advised to commit your pubspec.lock for app projects but not for libraries.

@moseskarunia
Copy link
Author

No, one of the transitive dependencies causes this since they are not locked. You should diff you pubspec.lock before and after the upgrade.
For this reason it is advised to commit your pubspec.lock for app projects but not for libraries.

Okay then. Thanks for the tip. But I think I'll still keep this issue opened because the error is happened on build_runner.

@jakemac53
Copy link
Contributor

@kuhnroyal it looks like you are hitting an unexpected variant somehow where a package exists as a dependency (maybe of one of your transitive deps), but it does not appear in your package_config.json file.

I would need more information to know exactly how this is happening...

@jakemac53
Copy link
Contributor

jakemac53 commented Jun 11, 2021

If you could try debugging your build script that might help, you can use these instructions https://github.com/dart-lang/build/blob/master/docs/builder_author_faq.md#how-can-i-debug-my-builder. Specifically it would be helpful to know exactly what package it is trying to look up when this fails - you can configure your debugger to stop on caught and uncaught exceptions and then see what the value of n and packageName are at that point (it should pause at the nodes[n]! expression here):

.addAll(packageDependencies[packageName]!.map((n) => nodes[n]!));

@moseskarunia
Copy link
Author

moseskarunia commented Jun 12, 2021

@kuhnroyal it looks like you are hitting an unexpected variant somehow where a package exists as a dependency (maybe of one of your transitive deps), but it does not appear in your package_config.json file.

I would need more information to know exactly how this is happening...

The problem is, on fresh install (either on CI or running flutter pub upgrade locally) removes connectivity dependency. This problem only surfaces on flutter 2.2.0. I didn't find this bug on flutter 2.0.6.

So the solution is by adding connectivity: 3.0.6 to my dev_dependency (I didn't have it in my dev or non dev dependency in the first place).

Now, both locally and in github CI, flutter pub run build_runner build --delete-conflicting-outputs run as expected.

@kuhnroyal
Copy link

Well, then one of your dependencies that you recently updated probably doesn't have connectivity as transitive dependency anymore. You should always try to declared every package that you import in the pubspec.yaml.

@moseskarunia
Copy link
Author

Well, then one of your dependencies that you recently updated probably doesn't have connectivity as transitive dependency anymore. You should always try to declared every package that you import in the pubspec.yaml.

My flutter app doesn't use connectivity at all. And the error only happens when generating / running build_runner. It run fine on debug run. And the only thing I changed to break it is by upgrading from flutter 2.0.6 to 2.2.0. Reverting back to 2.0.6 works immediately.

@jakemac53
Copy link
Contributor

I am not sure how to proceed here, but just for a bit more information on my end looking at the code, it appears that what must be happening is that some package has a dependency which exists as a dependency in its pubspec.yaml, but that does not have an entry in the .dart_tool/package_config.json file.

If I could have the full logs from the github actions run that might help - specifically from the flutter pub get step? I think you might want to add a --verbose to that as well because flutter hides all the useful logs from pub generally.

@jakemac53
Copy link
Contributor

Closing this as stale for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants