flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

gen runner fails with Bad state: No element

Open felix-barz-brickmakers opened this issue 2 years ago • 3 comments

The current version of flutter_gen_runner failes with the following error:

[SEVERE] flutter_gen_runner:flutter_gen_runner on $package$ (cached):

Bad state: No element
[SEVERE] Failed after 16.0s

Running the build runner in verbose mode does not reveal anything else about the error.

I tried deleting all image and font assets, but that did not fix the problem, so it seems it has nothing to do with a broken file or something like that. I attached the pubspec and lockfile of the project for reference.

pubspec.yaml.txt pubspec.lock.txt

felix-barz-brickmakers avatar Jun 10 '22 07:06 felix-barz-brickmakers

Thanks, we are getting this also in version 4.3.0. Version 4.1.6 still works.

FlutterGen v4.3.0 Loading ... pubspec.yaml [SEVERE] flutter_gen_runner:flutter_gen_runner on $package$:

Bad state: No element

jl-insiders avatar Jun 13 '22 21:06 jl-insiders

New infos: I found the position in the code where the exception is throw: It happens in https://github.com/FlutterGen/flutter_gen/blob/main/packages/runner/lib/flutter_gen_runner.dart#L62

Apparently, the buildStep.findAssets fails to find the pubspec.yaml. I checked with the debugger, and the config.pubspecFile.path correctly resolves to "pubspec.yaml"

Bildschirmfoto 2022-06-24 um 09 01 09

Note: This first broke in 4.2.0, where that file was greatly changed

felix-barz-brickmakers avatar Jun 24 '22 07:06 felix-barz-brickmakers

Maybe it's too late, but if you have a build.yaml file then adding - "pubspec.yaml" to source: will fix this; example:

targets:
  $default:
    sources:
      include:
        - "pubspec.yaml"       # add this line
        - $package$
        - assets/**
        - assets/i18n/**
        - lib/**
        - swaggers/**
    builders:
      swagger_dart_code_generator:
        options:
          input_folder: "swaggers/"
          output_folder: "lib/swaggers/gen/"

Ahmed-gubara avatar Sep 10 '22 21:09 Ahmed-gubara

Maybe it's too late, but if you have a build.yaml file then adding - "pubspec.yaml" to source: will fix this; example:

targets:
  $default:
    sources:
      include:
        - "pubspec.yaml"       # add this line
        - $package$
        - assets/**
        - assets/i18n/**
        - lib/**
        - swaggers/**
    builders:
      swagger_dart_code_generator:
        options:
          input_folder: "swaggers/"
          output_folder: "lib/swaggers/gen/"

@Ahmed-gubara I wrote the build.yaml as per your comment and the problem was solved. Thank you!

tihimsm avatar Oct 06 '22 01:10 tihimsm

Yes, this did work for me as well. Another fix would be to simply delete the build.yaml. My suggestion:

Add a "known issue" to the README, that when using a custom build.yaml, one has to add the "pubspec.yaml" line to the sources.

That would be enough for me and then the issue can be closed.

felix-barz-brickmakers avatar Oct 06 '22 06:10 felix-barz-brickmakers