dart-code-checker / dart-code-metrics

Software analytics tool that helps developers analyse and improve software quality.
https://dcm.dev
Other
860 stars 266 forks source link

[BUG] Upgraded to version 1.3.1, DCM crashes with `UnhandledException` #1220

Closed elliette closed 1 year ago

elliette commented 1 year ago

Environment and configuration

DCM version: 1.3.1 Dart SDK version: 3.0.0-290.3.beta

Link to configuration: https://github.com/dart-lang/webdev/blob/master/dwds/analysis_options.yaml

# TODO(https://github.com/dart-lang/webdev/issues/2053): Enable commented-out rules with fixes.
dart_code_metrics:
  metrics:
    # cyclomatic-complexity: 20 # Enable.
    # number-of-parameters: 5 # Enable.
    # maximum-nesting-level: 5 # Enable.
  metrics-exclude:
    - test/**
  rules:
    # - arguments-ordering 
    # - avoid-banned-imports
    - avoid-cascade-after-if-null
    - avoid-collection-methods-with-unrelated-types
    # - avoid-double-slash-imports
    - avoid-duplicate-exports
    # - avoid-dynamic
    # - avoid-global-state # Enable.
    # - avoid-ignoring-return-values
    # - avoid-late-keyword
    - avoid-missing-enum-constant-in-map
    - avoid-nested-conditional-expressions
    - avoid-non-ascii-symbols
    # - avoid-non-null-assertion # Enable.
    # - avoid-passing-async-when-sync-expected # Enable.
    - avoid-redundant-async
    # - avoid-throw-in-catch-block # Enable.
    # - avoid-top-level-members-in-tests
    # - avoid-unnecessary-conditionals
    - avoid-unnecessary-type-assertions
    - avoid-unnecessary-type-casts
    - avoid-unrelated-type-assertions
    - avoid-unused-parameters
    # - ban-name
    - binary-expression-operand-order
    - double-literal-format
    # - format-comment # Enable.
    # - list-all-equatable-fields
    # - member-ordering # Enable.
    # - missing-test-assertion
    # - new-line-before-return
    - no-boolean-literal-compare
    # - no-empty-block # Enable.
    # - no-equal-arguments
    - no-equal-then-else
    # - no-magic-number
    # - no-object-declaration
    # - prefer-async-await # Enable.
    # - prefer-commenting-analyzer-ignores # Enable.
    # - prefer-conditional-expressions
    # - prefer-correct-identifier-length
    # - prefer-correct-test-file-name # Enable.
    - prefer-correct-type-name
    - prefer-enums-by-name
    # - prefer-first
    # - prefer-immediate-return # Enable.
    - prefer-iterable-of
    - prefer-last
    # - prefer-match-file-name
    # - prefer-moving-to-variable: # Enable.
    #     allow-duplicated-chains: 2
    # - prefer-static-class
    # - prefer-trailing-comma
    # - tag-name

What did you do?

When running dcm analyze, saw:

🆕 Update available! 1.2.0 -> 1.3.0
To upgrade the executable, run: brew upgrade dcm

I upgraded DCM, and then ran dcm analyze again, got the following UnhandledException:

⠹ Analyzing 60 file(s)... 48msUnhandled exception:
FormatException: Unexpected extension byte (at offset 0)
#0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1747)
#1      Utf8Decoder.convert (dart:convert/utf.dart:351)
#2      Utf8Codec.decode (dart:convert/utf.dart:63)
#3      SummaryDataReader.readStringUtf8 (package:analyzer_core/src/summary2/data_reader.dart:102)
#4      SummaryDataReader.readTypedList.<anonymous closure> (package:analyzer_core/src/summary2/data_reader.dart:125)
#5      new _List.generate (dart:core-patch/array.dart:112)
#6      SummaryDataReader.readTypedList (package:analyzer_core/src/summary2/data_reader.dart:124)
#7      SummaryDataReader.readStringUtf8List (package:analyzer_core/src/summary2/data_reader.dart:106)
#8      new UnlinkedCombinator.read (package:analyzer_core/src/dart/analysis/unlinked_data.dart:110)
#9      new UnlinkedLibraryImportDirective.read.<anonymous closure> (package:analyzer_core/src/dart/analysis/unlinked_data.dart:232)
#10     SummaryDataReader.readTypedList.<anonymous closure> (package:analyzer_core/src/summary2/data_reader.dart:125)
#11     new _List.generate (dart:core-patch/array.dart:112)
#12     SummaryDataReader.readTypedList (package:analyzer_core/src/summary2/data_reader.dart:124)
#13     new UnlinkedLibraryExportDirective.read (package:analyzer_core/src/dart/analysis/unlinked_data.dart:187)
#14     new UnlinkedUnit.read.<anonymous closure> (package:analyzer_core/src/dart/analysis/unlinked_data.dart:509)
#15     SummaryDataReader.readTypedList.<anonymous closure> (package:analyzer_core/src/summary2/data_reader.dart:125)
#16     new _List.generate (dart:core-patch/array.dart:112)
#17     SummaryDataReader.readTypedList (package:analyzer_core/src/summary2/data_reader.dart:124)
#18     new UnlinkedUnit.read (package:analyzer_core/src/dart/analysis/unlinked_data.dart:508)
#19     new AnalysisDriverUnlinkedUnit.read (package:analyzer_core/src/dart/analysis/unlinked_data.dart:24)
#20     new AnalysisDriverUnlinkedUnit.fromBytes (package:analyzer_core/src/dart/analysis/unlinked_data.dart:18)
#21     FileState._getUnlinkedUnit (package:analyzer_core/src/dart/analysis/file_state.dart:632)
#22     FileState.refresh (package:analyzer_core/src/dart/analysis/file_state.dart:511)
#23     FileSystemState._newFile (package:analyzer_core/src/dart/analysis/file_state.dart:1285)
#24     FileSystemState.getFileForUri (package:analyzer_core/src/dart/analysis/file_state.dart:1214)
#25     AnalysisDriver._discoverDartCore (package:analyzer_core/src/dart/analysis/driver.dart:1481)
#26     AnalysisDriver.performWork (package:analyzer_core/src/dart/analysis/driver.dart:1004)
#27     AnalysisDriverScheduler._run (package:analyzer_core/src/dart/analysis/driver.dart:2075)
<asynchronous suspension>

Note: If I switch my Dart SDK to Dart stable (2.19.6), I see:

⠹ Analyzing 60 file(s)... 48msOops; metrics has exited unexpectedly: "FormatException: Unexpected extension byte (at offset 39)"

What did you expect to happen?

DCM to not throw an exception

What actually happened?

DCM threw an exception

Participation

Additional comments

No response

incendial commented 1 year ago

@elliette please delete the .dartServer/dart-code-metrics-teams/ folder and sorry for inconvenience. Won't happen again in the future releases.

elliette commented 1 year ago

Deleting .dartServer/dart-code-metrics-teams/ fixed this, thanks!