Error using library which uses DartSON

Issue

I built a simple Dart library to wrap the Mastodon (social platform) API – (source at https://github.com/mykdavies/Mastodon).

I can use the library locally in another project by adding the appropriate dependency to its pubspec.yaml:

dependencies:
  ...
  mastodon:
    path: /Users/mike/Documents/Development/dart/mastodon

and everything works fine.

I have published it to pub (https://pub.dartlang.org/packages/mastodon), but when I change my pubspec to use this version:

dependencies:
  ...
  mastodon:
    ^0.1.0

I get a problem with the Dartson transformers. Can anyone help me understand what’s going wrong?

Thanks, Michael


Full pubspec:

name: rssToot
description: A sample command-line application.
version: 0.0.1

environment:
  sdk: '>=1.20.1 <2.0.0'

dependencies:
  dart_feed: "^0.0.4"
  oauth2: ^1.0.2
  mime: ^0.9.2
  mastodon:
    ^0.1.0

dev_dependencies:
  test: ^0.12.0

Full stack-trace:

Resolving dependencies...
> mastodon 0.1.0 (was 0.0.5)
Downloading mastodon 0.1.0...
Changed 1 dependency!
Precompiling dependencies...
Loading source assets...
Loading dartson transformers...
Transform Dartson on mastodon|lib/src/mastodon_base.dart threw error: The getter 'name' was called on null.
Receiver: null
Tried calling: name
dart:core-patch/object_patch.dart 43       Object._noSuchMethod
dart:core-patch/object_patch.dart 47       Object.noSuchMethod
package:dartson/transformer.dart 218       FileCompiler.buildEntityMap.<fn>
dart:collection/list.dart 63               Object&ListMixin.forEach
package:dartson/transformer.dart 213       FileCompiler.buildEntityMap
package:dartson/transformer.dart 132       FileCompiler._prepareEntities.<fn>
dart:core-patch/growable_array.dart 256    List.forEach
package:dartson/transformer.dart 131       FileCompiler._prepareEntities
package:dartson/transformer.dart 104       FileCompiler.build
package:dartson/transformer.dart 55        DartsonTransformer.apply.<fn>
dart:async/zone.dart 1371                  _RootZone.runUnary
dart:async/future_impl.dart 129            _FutureListener.handleValue
dart:async/future_impl.dart 631            _Future._propagateToListeners.handleValueCallback
dart:async/future_impl.dart 660            _Future._propagateToListeners
dart:async/future_impl.dart 474            _Future._completeWithValue
dart:async/future_impl.dart 522            _Future._asyncComplete.<fn>
dart:async/schedule_microtask.dart 41      _microtaskLoop
dart:async/schedule_microtask.dart 50      _startMicrotaskLoop
dart:isolate-patch/isolate_patch.dart 99   _runPendingImmediateCallback
dart:isolate-patch/isolate_patch.dart 152  _RawReceivePortImpl._handleMessage

dart:core                             Object.noSuchMethod
package:dartson/transformer.dart 218  FileCompiler.buildEntityMap.<fn>
dart:collection                       Object&ListMixin.forEach
package:dartson/transformer.dart 213  FileCompiler.buildEntityMap
package:dartson/transformer.dart 132  FileCompiler._prepareEntities.<fn>
dart:core                             List.forEach
package:dartson/transformer.dart 131  FileCompiler._prepareEntities
package:dartson/transformer.dart 104  FileCompiler.build
package:dartson/transformer.dart 55   DartsonTransformer.apply.<fn>
package:pub/src/entrypoint.dart 269                                              Entrypoint._precompileDependencies.<fn>
===== asynchronous gap ===========================
package:pub/src/log.dart 408                                                     progress
package:pub/src/entrypoint.dart 254                                              Entrypoint._precompileDependencies
===== asynchronous gap ===========================
package:pub/src/entrypoint.dart 226                                              Entrypoint.acquireDependencies
===== asynchronous gap ===========================
package:pub/src/command/get.dart 38                                              GetCommand.run
package:args/command_runner.dart 194                                             CommandRunner.runCommand
===== asynchronous gap ===========================
package:pub/src/command_runner.dart 168                                          PubCommandRunner.runCommand.<fn>
dart:async                                                                       Future.Future.sync
package:pub/src/utils.dart 99                                                    captureErrors.<fn>
dart:async                                                                       runZoned
package:pub/src/utils.dart 118                                                   captureErrors
package:pub/src/command_runner.dart 168                                          PubCommandRunner.runCommand
===== asynchronous gap ===========================
package:pub/src/command_runner.dart 117                                          PubCommandRunner.run
===== asynchronous gap ===========================
/b/build/slave/dart-sdk-mac-stable/build/sdk/third_party/pkg/pub/bin/pub.dart 8  main
Process finished with exit code 0

Solution

Try to do a clean checkout of your git repository locally, and use the initialization there. It may be possible that for some reason the dartson transformer didn’t pick up a change from 0.0.5 -> 0.1.0, used some cached value, and didn’t complain while you were developing it.

Answered By – István

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.