invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
283 stars 64 forks source link

custom_lint fails with "Failed to decode" on unrelated files. #268

Closed felix-barz-brickmakers closed 1 month ago

felix-barz-brickmakers commented 2 months ago

Describe the bug When trying to run custom_lint on a more complex flutter project, it fails with Failed to decode .dart_tool/package_config.json on unrelated files. This happens for:

The error is the same in all cases (with different paths):

PathNotFoundException: Cannot open file, path = '.../.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)
#2      _rootRunUnary (dart:async/zone.dart:1407:47)
#3      _CustomZone.runUnary (dart:async/zone.dart:1308:19)
<asynchronous suspension>
#4      _File.readAsBytes.<anonymous closure> (dart:io/file_impl.dart:562:24)
<asynchronous suspension>
#5      parsePackageConfig (package:custom_lint_core/src/package_utils.dart:161:5)
<asynchronous suspension>
#6      CustomLintProject.parse (package:custom_lint/src/workspace.dart:1025:34)
<asynchronous suspension>
#7      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#8      CustomLintWorkspace.fromContextRoots (package:custom_lint/src/workspace.dart:516:22)
<asynchronous suspension>
#9      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:90:25)
<asynchronous suspension>
#10     _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
<asynchronous suspension>
#11     _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:126:19)
<asynchronous suspension>
#12     _runServer (package:custom_lint/custom_lint.dart:86:3)
<asynchronous suspension>
#13     customLint (package:custom_lint/custom_lint.dart:50:5)
<asynchronous suspension>
#14     entrypoint (file:///Users/user/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:68:3)
<asynchronous suspension>
#15     main (file:///Users/user/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:80:5)
<asynchronous suspension>

#0      CustomLintProject.parse.<anonymous closure> (package:custom_lint/src/workspace.dart:1028:7)
#1      _rootRunBinary (dart:async/zone.dart:1423:47)
#2      _CustomZone.runBinary (dart:async/zone.dart:1315:19)
#3      _FutureListener.handleError (dart:async/future_impl.dart:178:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:873:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:894:13)
#6      Future._completeError (dart:async/future_impl.dart:674:5)
<asynchronous suspension>

To Reproduce (Example project: test_project.zip)

Expected behavior The tool should run without any errors.

Workaround For now, the only workaround seems to be to delete the ios/.symlinks and .dart_tool/flutter_gen directories prior to executing dart run custom_lint.

tatsuyukiDunqian commented 2 months ago

I encountered the same issue with custom_lint: 0.6.5, and the problem was only resolved after downgrading to version 0.6.4.

lishaduck commented 2 months ago

For me, I ran flutter clean and that fixed it, for now. It'll probably break next time I build the app, but it works in CI at least.