dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.59k forks source link

Improve diagnostic reporting on invalid analysis options #56943

Open MohammadNezarAldalati opened 1 month ago

MohammadNezarAldalati commented 1 month ago
Internal error: Failed to handle request: analysis.setAnalysisRoots
Null check operator used on a null value
#0      _LintConfig._parseYaml.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:analyzer/src/lint/config.dart:161:48)
#1      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:286:8)
#2      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#3      CastMap.forEach (dart:_internal/cast.dart:285:13)
#4      MapView.forEach (dart:collection/maps.dart:347:10)
#5      _LintConfig._parseYaml.<anonymous closure>.<anonymous closure> (package:analyzer/src/lint/config.dart:155:54)
#6      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:286:8)
#7      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#8      CastMap.forEach (dart:_internal/cast.dart:285:13)
#9      MapView.forEach (dart:collection/maps.dart:347:10)
#10     _LintConfig._parseYaml.<anonymous closure> (package:analyzer/src/lint/config.dart:144:46)
#11     _HashMap.forEach (dart:collection-patch/collection_patch.dart:153:15)
#12     MapView.forEach (dart:collection/maps.dart:347:10)
#13     _LintConfig._parseYaml (package:analyzer/src/lint/config.dart:117:16)
#14     new LintConfig.parseMap (package:analyzer/src/lint/config.dart:38:62)
#15     parseConfig (package:analyzer/src/lint/config.dart:15:25)
#16     AnalysisOptionsImplExtensions.applyOptions (package:analyzer/src/analysis_options/apply_options.dart:229:18)
#17     ContextBuilderImpl._createOptionsMap (package:analyzer/src/dart/analysis/context_builder.dart:210:15)
#18     ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:135:15)
#19     new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:108:36)
#20     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package:analysis_server/src/context_manager.dart:549:40)
<asynchronous suspension>
#21     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded (package:analysis_server/src/context_manager.dart:694:11)
<asynchronous suspension>
#22     _CancellingTaskQueue.queue.<anonymous closure> (package:analysis_server/src/context_manager.dart:978:15)
<asynchronous suspension>
#23     ContextManagerImpl.setRoots (package:analysis_server/src/context_manager.dart:364:5)
<asynchronous suspension>
#24     LegacyAnalysisServer.setAnalysisRoots (package:analysis_server/src/legacy_analysis_server.dart:793:9)
<asynchronous suspension>
#25     AnalysisSetAnalysisRootsHandler.handle (package:analysis_server/src/handler/legacy/analysis_set_analysis_roots.dart:46:7)
<asynchronous suspension>
#26     LegacyAnalysisServer.handleRequest.<anonymous closure>.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:577:11)
<asynchronous suspension>
#27     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#28     LegacyAnalysisServer.handleRequest.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:558:7)
<asynchronous suspension>

null
[RequestError code: SERVER_ERROR, message: Null check operator used on a null value]

General info

Project info

dart-github-bot commented 1 month ago

Summary: The user is experiencing an error when running dart analyze in a new Flutter project. The error message indicates a null check operator used on a null value, likely stemming from an issue with parsing the lint configuration file.

MohammadNezarAldalati commented 1 month ago
mraleph commented 1 month ago

This still should not just crash but should report a readable error.

mraleph commented 1 month ago

cc @pq

pq commented 1 month ago

The unsafe null check was fixed by @DanTup in https://github.com/dart-lang/sdk/commit/bbe6f2340ad983e2a08b185e2a6555cc13cb0179. We do have some analysis options validation so in common cases errors will be reported.

@MohammadNezarAldalati if you can reproduce the file in a state that crashes for you I can look and see if we're reporting anything on it today.

Thanks!

MohammadNezarAldalati commented 1 month ago

@pq I just wrote a none valid yaml by mistake in analysis_options.yaml and that what cause the error when run dart analyze:

linter:
  rules:
    analyzer:
      plugins:
        - custom_lint

and then I notice it and fix it:

linter:
  rules:

analyzer:
  plugins:
    - custom_lint
pq commented 1 month ago

Great. Thanks!