Skip to content

Analysis failure when analysis_options.yaml is malformed #56811

Open
@abitofevrything

Description

@abitofevrything

dart analyze and the dart analysis server both fail when analysis_options.yaml contains malformed data.

Notably, dart analyze outputs a single error and then hangs forever:

Error from the analysis server: Internal error: Failed to handle request: analysis.setAnalysisRoots
type 'Null' is not a subtype of type 'Object' in type cast
#0      YamlNodeExtension.valueOrThrow (package:analyzer/src/util/yaml.dart:147:36)
#1      _LintConfig.asBool (package:analyzer/src/lint/config.dart:77:47)
#2      _LintConfig._parseYaml.<anonymous closure>.<anonymous closure> (package:analyzer/src/lint/config.dart:146:19)
#3      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:286:8)
#4      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#5      CastMap.forEach (dart:_internal/cast.dart:285:13)
#6      MapView.forEach (dart:collection/maps.dart:347:10)
#7      _LintConfig._parseYaml.<anonymous closure> (package:analyzer/src/lint/config.dart:144:46)
#8      _HashMap.forEach (dart:collection-patch/collection_patch.dart:153:15)
#9      MapView.forEach (dart:collection/maps.dart:347:10)
#10     _LintConfig._parseYaml (package:analyzer/src/lint/config.dart:117:16)
#11     new LintConfig.parseMap (package:analyzer/src/lint/config.dart:38:62)
#12     parseConfig (package:analyzer/src/lint/config.dart:15:25)
#13     AnalysisOptionsImplExtensions.applyOptions (package:analyzer/src/analysis_options/apply_options.dart:229:18)
#14     ContextBuilderImpl._createOptionsMap (package:analyzer/src/dart/analysis/context_builder.dart:210:15)
#15     ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:135:15)
#16     new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:108:36)
#17     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package:analysis_server/src/context_manager.dart:549:40)
<asynchronous suspension>
#18     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded (package:analysis_server/src/context_manager.dart:694:11)
<asynchronous suspension>
#19     _CancellingTaskQueue.queue.<anonymous closure> (package:analysis_server/src/context_manager.dart:978:15)
<asynchronous suspension>
#20     ContextManagerImpl.setRoots (package:analysis_server/src/context_manager.dart:364:5)
<asynchronous suspension>
#21     LegacyAnalysisServer.setAnalysisRoots (package:analysis_server/src/legacy_analysis_server.dart:793:9)
<asynchronous suspension>
#22     AnalysisSetAnalysisRootsHandler.handle (package:analysis_server/src/handler/legacy/analysis_set_analysis_roots.dart:46:7)
<asynchronous suspension>
#23     LegacyAnalysisServer.handleRequest.<anonymous closure>.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:577:11)
<asynchronous suspension>
#24     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#25     LegacyAnalysisServer.handleRequest.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:558:7)
<asynchronous suspension>



null
Error response from the server: SERVER_ERROR type 'Null' is not a subtype of type 'Object' in type cast
#0      YamlNodeExtension.valueOrThrow (package:analyzer/src/util/yaml.dart:147:36)
#1      _LintConfig.asBool (package:analyzer/src/lint/config.dart:77:47)
#2      _LintConfig._parseYaml.<anonymous closure>.<anonymous closure> (package:analyzer/src/lint/config.dart:146:19)
#3      CastMap.forEach.<anonymous closure> (dart:_internal/cast.dart:286:8)
#4      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#5      CastMap.forEach (dart:_internal/cast.dart:285:13)
#6      MapView.forEach (dart:collection/maps.dart:347:10)
#7      _LintConfig._parseYaml.<anonymous closure> (package:analyzer/src/lint/config.dart:144:46)
#8      _HashMap.forEach (dart:collection-patch/collection_patch.dart:153:15)
#9      MapView.forEach (dart:collection/maps.dart:347:10)
#10     _LintConfig._parseYaml (package:analyzer/src/lint/config.dart:117:16)
#11     new LintConfig.parseMap (package:analyzer/src/lint/config.dart:38:62)
#12     parseConfig (package:analyzer/src/lint/config.dart:15:25)
#13     AnalysisOptionsImplExtensions.applyOptions (package:analyzer/src/analysis_options/apply_options.dart:229:18)
#14     ContextBuilderImpl._createOptionsMap (package:analyzer/src/dart/analysis/context_builder.dart:210:15)
#15     ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:135:15)
#16     new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:108:36)
#17     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded.performContextRebuild (package:analysis_server/src/context_manager.dart:549:40)
<asynchronous suspension>
#18     ContextManagerImpl._createAnalysisContexts.performContextRebuildGuarded (package:analysis_server/src/context_manager.dart:694:11)
<asynchronous suspension>
#19     _CancellingTaskQueue.queue.<anonymous closure> (package:analysis_server/src/context_manager.dart:978:15)
<asynchronous suspension>
#20     ContextManagerImpl.setRoots (package:analysis_server/src/context_manager.dart:364:5)
<asynchronous suspension>
#21     LegacyAnalysisServer.setAnalysisRoots (package:analysis_server/src/legacy_analysis_server.dart:793:9)
<asynchronous suspension>
#22     AnalysisSetAnalysisRootsHandler.handle (package:analysis_server/src/handler/legacy/analysis_set_analysis_roots.dart:46:7)
<asynchronous suspension>
#23     LegacyAnalysisServer.handleRequest.<anonymous closure>.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:577:11)
<asynchronous suspension>
#24     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#25     LegacyAnalysisServer.handleRequest.<anonymous closure> (package:analysis_server/src/legacy_analysis_server.dart:558:7)
<asynchronous suspension>


Analyzing flutter_project_amit_63_ibrahim_juma...                      |

This issue also causes the analysis server to fail to start, which means IDEs appear to be misconfigured and do not report errors or other lints.

In this case, the analysis_options.yaml causing the issue was the following:

include: package:flutter_lints/flutter.yaml

analyzer:
  errors:
    unused_import: ignore

    avoid_print: ignore
    prefer_const_constructors: ignore
    prefer_const_literals_to_create_immutables: ignore
    prefer_const_constructors_in_immutables: ignore
    prefer_final_fields: ignore
    sized_box_for_whitespace: ignore
    use_key_in_widget_constructors: ignore
    must_be_immutable: ignore
    prefer_typing_uninitialized_variables: ignore
    sort_child_properties_last: ignore
    unnecessary_string_interpolations: ignore
    body_might_complete_normally_nullable: ignore
    depend_on_referenced_packages: ignore

linter:
  rules:
    prefer_const_constructors:
    prefer_single_quotes: true

(note the missing value after prefer_const_constructors).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-analysis-optionsanalyzer-crash-reportIssues which have been reported due to an analysis server crasharea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions