Skip to content

Null check operator used on a null value while using serverpod generate #963

Closed

Description

@dirkschut

Describe the bug
While using serverpod generate on a project with the following code, I get the following error:

In example_endpoint.dart, I added this in the ExampleEndpoint class:

  Future<Article> test(Session session) async{
    return Article(
      title: 'Test Title',
    );
  }

I added article.yaml in the protocol folder with the following content:

class: Article
fields:
  title: String

This is the output from serverpod generate:

WARNING! Windows is not officially supported yet. Things may or may not work as expected.

Yikes! It is possible that this error is caused by an internal issue with the Serverpod tooling. We would appreciate if you filed an issue over at Github. Please include the stack trace below and describe any steps you did to trigger the error.
https://github.com/serverpod/serverpod/issues
Null check operator used on a null value
#0      new TypeDefinition.fromDartType (package:serverpod_cli/src/generator/types.dart:75:49)
#1      new TypeDefinition.fromDartType.<anonymous closure> (package:serverpod_cli/src/generator/types.dart:70:56)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:47:28)
#7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
#8      new TypeDefinition.fromDartType (package:serverpod_cli/src/generator/types.dart:70:73)
#9      EndpointsAnalyzer.analyze (package:serverpod_cli/src/analyzer/dart/endpoints_analyzer.dart:168:48)
<asynchronous suspension>
#10     performGenerate (package:serverpod_cli/src/generator/generator.dart:46:19)
<asynchronous suspension>
#11     _main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:221:7)
<asynchronous suspension>
#12     main.<anonymous closure> (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:36:9)
<asynchronous suspension>
#13     main (file:///C:/Users/dschu/AppData/Local/Pub/Cache/hosted/pub.dev/serverpod_cli-1.1.1/bin/serverpod_cli.dart:33:3)
<asynchronous suspension>

To Reproduce
Steps to reproduce the behavior:

  1. Be on Windows
  2. Create a new empty project
  3. Add the provided code
  4. Run serverpod generate
  5. See error

Expected behavior
Code should be generated for the client to use.

Serverpod versions

  • CLI Version: 1.1.1
  • Library version: ^1.1.1

Platform information
Windows 11, latest updates. WSL is Ubuntu.

Additional context
I'm a serverpod noob (just started playing with it today), and couldn't figure out what to do with my google fu, but the CLI said to report it here, so here I am.

Activity

  1. changed the title [-]Null check operator used on a null value white using serverpod generate[/-] [+]Null check operator used on a null value while using serverpod generate[/+] on May 29, 2023
  2. Isakdl commented on May 29, 2023

    @Isakdl
    Collaborator

    Just ran a test on this.

    The issue is that you have not imported the Article class into your Endpoint file. Put import '../generated/article.dart'; at the top of the example_endpoint.dart and you should be able to get things to work.

    The generate command would also work if you simply delete this code:

    Future<Article> test(Session session) async{
      return Article(
        title: 'Test Title',
      );
    }

    Since that would remove the reference to the class we cannot find.

    With that said this error is a bug on Windows, we should give a better error message here rather than crash on a null pointer. So thank you very much for the report! :).

  3. added
    bug
    on May 29, 2023
  4. dirkschut commented on May 29, 2023

    @dirkschut
    Author

    Thanks for the help. I didn't know you had to explicitly import the file. More explicit error messages would certainly be very helpful. I'll test your solution once I can find a moment to get in front of my PC.

  5. dirkschut commented on May 29, 2023

    @dirkschut
    Author

    Thanks. Awesome to see you implement a fix so fast. Your fix did indeed work and I'm now happily exploring Serverpod once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions