Incredible work so far with the project. I implemented enhanced enums and discovered this reproducible error when using my postgresql database.
"conduit build" WILL work in these circumstances:
- Create a model
- Link a function without database connectivity
"conduit build" WILL NOT work in this circumstance:
- Creation of a database model with various GET and POST request handling
To Reproduce
Steps to reproduce the behavior:
- Create a sample enum
enum SampleEnum {
one,
two,
three,
four,
five,
six,
seven;
static SampleEnum parse(String value) {
switch (value) {
case 'one':
return SampleEnum.one;
case 'two':
return SampleEnum.two;
case 'three':
return SampleEnum.three;
case 'four':
return SampleEnum.four;
case 'five':
return SampleEnum.five;
case 'six':
return SampleEnum.six;
case 'seven':
return SampleEnum.seven;
default:
throw Exception('Unknown enum value: $value');
}
}
@override
String toString() {
switch (this) {
case SampleEnum.one:
return 'one';
case SampleEnum.two:
return 'two';
case SampleEnum.three:
return 'three';
case SampleEnum.four:
return 'four';
case SampleEnum.five:
return 'five';
case SampleEnum.six:
return 'six';
case SampleEnum.seven:
return 'seven';
}
}
}
- Create a test model
import 'package:conduit/conduit.dart';
import 'package:conduit_bug/sample_enum.dart';
class TestModel extends ManagedObject<_TestModel> implements _TestModel {}
@Table(name: "Tests")
class _TestModel {
@primaryKey
int? id;
SampleEnum? testValue;
}
- Create a test controller
import 'package:conduit/conduit.dart';
import 'package:conduit_bug/sample_enum.dart';
import 'package:conduit_bug/test_model.model.dart';
class TestController extends ResourceController {
TestController(this.context);
final ManagedContext context;
@Operation.get()
Future<Response> getAll() async {
final query = Query<TestModel>(context);
final results = await query.fetch();
return Response.ok(results);
}
@Operation.post()
Future<Response> handleCreation() async {
if (request != null) {
final Map<String, dynamic> map = request!.body.as<Map<String, dynamic>>();
final query = Query<TestModel>(context)
..values.testValue = SampleEnum.parse(map['value'] as String? ?? "");
final result = await query.insert();
print("Object ${result.id} created");
return Response.ok(result);
} else {
logger.log(Level.WARNING, 'Invalid request received');
return Response.badRequest(body: {"error": "request is invalid"});
}
}
}
- Update the channel
import 'package:conduit_bug/conduit_bug.dart';
import 'package:conduit_bug/sample_enum.dart';
import 'package:conduit_bug/test_controller.dart';
class ConduitBugChannel extends ApplicationChannel {
late ManagedContext context;
@override
Future prepare() async {
print("Application started on port: ${options!.port}.");
logger.onRecord.listen(
(rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
final persistentStore = PostgreSQLPersistentStore.fromConnectionInfo(
"postgres",
"",
"localhost",
5432,
"bug_submission",
);
context = ManagedContext(
ManagedDataModel.fromCurrentMirrorSystem(), persistentStore);
}
@override
Controller get entryPoint {
final router = Router();
router.route("handle").link(() => TestController(context));
return router;
}
}
- Execute conduit build
Expected behavior
AOT compilation is expected to compile successfully
Output
➜ conduit_bug conduit build
-- Conduit CLI Version: 3.1.2
-- Conduit project version: 3.1.2
Resolving ASTs...
Generating runtime...
Generated runtime at 'file:///..../conduit_bug/build/generated_runtime/'.
Compiling package 'conduit_runtime'...
Package 'conduit_runtime' compiled to 'file:///...../conduit_bug/build/packages/conduit_runtime/'.
Compiling package 'conduit'...
Package 'conduit' compiled to 'file:///...../conduit_bug/build/packages/conduit/'.
Compiling package 'conduit_config'...
Package 'conduit_config' compiled to 'file:///...../conduit_bug/build/packages/conduit_config/'.
Copying application package (from 'file:///...../conduit_bug/')...
Application packaged copied to 'file:///....../conduit_bug/build/packages/conduit_bug/'.
Fetching dependencies (--offline --no-precompile)...
Finished fetching dependencies.
Compiling...
*** Uncaught error
Bad state: Bad state: 'dart2native' failed with the following message: Info: Compiling with sound null safety
../../generated_runtime/lib/src/testmodel.dart:31:53: Error: 'SampleEnum' isn't a type.
, 'testValue': ManagedAttributeDescription.make(entity, 'testValue',
^^^^^^^^^^
../../generated_runtime/lib/src/testmodel.dart:32:22: Error: 'SampleEnum' isn't a type.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^^^^^^^^
../../generated_runtime/lib/src/testmodel.dart:43:46: Error: 'SampleEnum' isn't a type.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^^^^^^^^
../../generated_runtime/lib/src/testmodel.dart:32:76: Error: The getter 'one' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'one'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^
../../generated_runtime/lib/src/testmodel.dart:32:87: Error: The getter 'two' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'two'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^
../../generated_runtime/lib/src/testmodel.dart:32:100: Error: The getter 'three' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'three'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^^^
../../generated_runtime/lib/src/testmodel.dart:32:114: Error: The getter 'four' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'four'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^^
../../generated_runtime/lib/src/testmodel.dart:32:127: Error: The getter 'five' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'five'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^^
../../generated_runtime/lib/src/testmodel.dart:32:139: Error: The getter 'six' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'six'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^
../../generated_runtime/lib/src/testmodel.dart:32:152: Error: The getter 'seven' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'seven'.
ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}),
^^^^^
../../generated_runtime/lib/src/testmodel.dart:42:27: Error: The getter 'one' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'one'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^
../../generated_runtime/lib/src/testmodel.dart:42:31: Error: The getter 'two' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'two'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^
../../generated_runtime/lib/src/testmodel.dart:42:35: Error: The getter 'three' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'three'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^^^
../../generated_runtime/lib/src/testmodel.dart:42:41: Error: The getter 'four' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'four'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^^
../../generated_runtime/lib/src/testmodel.dart:42:46: Error: The getter 'five' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'five'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^^
../../generated_runtime/lib/src/testmodel.dart:42:51: Error: The getter 'six' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'six'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^
../../generated_runtime/lib/src/testmodel.dart:42:55: Error: The getter 'seven' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'seven'.
return [Validate.oneOf([one,two,three,four,five,six,seven])].map((v) {
^^^^^
../../generated_runtime/lib/src/testmodel.dart:43:100: Error: The getter 'one' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'one'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^
../../generated_runtime/lib/src/testmodel.dart:43:111: Error: The getter 'two' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'two'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^
../../generated_runtime/lib/src/testmodel.dart:43:124: Error: The getter 'three' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'three'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^^^
../../generated_runtime/lib/src/testmodel.dart:43:138: Error: The getter 'four' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'four'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^^
../../generated_runtime/lib/src/testmodel.dart:43:151: Error: The getter 'five' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'five'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^^
../../generated_runtime/lib/src/testmodel.dart:43:163: Error: The getter 'six' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'six'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^
../../generated_runtime/lib/src/testmodel.dart:43:176: Error: The getter 'seven' isn't defined for the class 'ManagedEntityRuntimeImpl'.
- 'ManagedEntityRuntimeImpl' is from 'package:generated_runtime/src/testmodel.dart' ('../../generated_runtime/lib/src/testmodel.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'seven'.
final state = v.compile(ManagedType.make(ManagedPropertyType.string, null, {'one': one,'two': two,'three': three,'four': four,'five': five,'six': six,'seven': seven}), relationshipInverseType: null);
^^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!
**** Stacktrace
- #0 Build.compile (package:conduit_runtime/src/build.dart:150:7)
-
- #1 Build.execute (package:conduit_runtime/src/build.dart:114:7)
-
- #2 BuildExecutable.execute (data:application/dart:13:252)
-
- #3 main (data:application/dart:9:18)
-
Desktop (please complete the following information):
Macbook M1
MacOs Monterey 12.3.1
Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "macos_arm64"
Pubspec.yml
environment:
sdk: ">=2.17.0 <3.0.0"
dependencies:
conduit: ^3.0.0
dev_dependencies:
test: ^1.16.5
conduit_test: ^3.0.0