Repository navigation
Closed
Labels
bugSomething isn't working
Description
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: StringThis 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:
- Be on Windows
- Create a new empty project
- Add the provided code
- Run serverpod generate
- 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.
Reacted by kemalinnowise
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
[-]Null check operator used on a null value white using serverpod generate[/-][+]Null check operator used on a null value while using serverpod generate[/+]Isakdl commentedon May 29, 2023
Just ran a test on this.
The issue is that you have not imported the
Articleclass into your Endpoint file. Putimport '../generated/article.dart';at the top of theexample_endpoint.dartand you should be able to get things to work.The generate command would also work if you simply delete this code:
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! :).
dirkschut commentedon May 29, 2023
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.
dirkschut commentedon May 29, 2023
Thanks. Awesome to see you implement a fix so fast. Your fix did indeed work and I'm now happily exploring Serverpod once again.