Back

Failing to execute functions: Error Msg:{"error":"type 'Null' is not a subtype of type 'String'"}

  • 0
  • Flutter
  • Functions
conqueror
6 May, 2023, 00:28

yes

TL;DR
The user is experiencing an error message stating "type 'Null' is not a subtype of type 'String'". The error is occurring when trying to print the payload. The user realizes that they need to create the variable before trying to print it. The error is also occurring when executing the function in the Appwrite console due to environment variable not being set. In order to fix this, the user should define the function name as "start" instead of "main". The user also mentions that the error could be happening before the print statement. The user is trying to print the payload in the response section and in the console, but it
Drake
6 May, 2023, 00:32

Okay it should be the same then

conqueror
6 May, 2023, 00:34

for checking how can i print payload in console or log

Drake
6 May, 2023, 00:35

Use print() but make sure to pass it a string

conqueror
6 May, 2023, 00:38

here is raw data ```{ "$id": "6452d0f3ce9edca1866d", "$createdAt": "2023-05-05T23:56:37.807+00:00", "$updatedAt": "2023-05-06T00:37:35.262+00:00", "execute": [

], "name": "func", "enabled": true, "runtime": "dart-2.17", "deployment": "6455a13c9026fb596952", "vars": [

], "events": [

], "schedule": "", "scheduleNext": "", "schedulePrevious": "", "timeout": 15 }```

conqueror
6 May, 2023, 00:43

payload is not printing in response nor in console, print( response.json(payload.toString())); print(payload.toString());

Drake
6 May, 2023, 00:44

Why are you calling response.json() like that?

Drake
6 May, 2023, 00:45

Also your error could be happening before the print

conqueror
6 May, 2023, 00:47

not using that

Drake
6 May, 2023, 00:48

Sorry, what?

conqueror
6 May, 2023, 00:51

just mistakenly copied, trying to see whether it prints on response section or not( or happening something in console).

conqueror
6 May, 2023, 00:53

here is the trace {"error":"type 'Null' is not a subtype of type 'String'#0 start (package:appwrite_function\/main.dart:10)\n#1 main.<anonymous closure>.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:37)\n#2 main.<anonymous closure>.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:36)\n#3 _rootRun (dart:async\/zone.dart:1426)\n#4 _CustomZone.run (dart:async\/zone.dart:1328)\n#5 _runZoned (dart:async\/zone.dart:1861)\n#6 runZonedGuarded (dart:async\/zone.dart:1849)\n#7 main.<anonymous closure> (file:\/\/\/usr\/local\/src\/server.dart:35)\n<asynchronous suspension>\n#8 handleRequest (package:shelf\/shelf_io.dart:138)\n<asynchronous suspension>\n"}

Drake
6 May, 2023, 00:54

And your file is named main.dart? If so, the problem is around line 10

conqueror
6 May, 2023, 00:56

yes

conqueror
6 May, 2023, 00:58

here is file structure

conqueror
6 May, 2023, 01:00

also change function name (at line 10) main to mainfunc but still giving the same error

Drake
6 May, 2023, 01:02

Wait line 10 was the function name?

Drake
6 May, 2023, 01:02

It should be start...

conqueror
6 May, 2023, 01:03

yes its function name define inside ServerAppwrite class

conqueror
6 May, 2023, 01:07

do you mean i have to define main then call this start inside main, right ?

conqueror
6 May, 2023, 02:13

why its printing Environment variables are not set. Function cannot use Appwrite SDK. executing this function in appwirte console ```Future<void> start(final req, final res) async { final client = Client();

// Uncomment the services you need, delete the ones you don't // final account = Account(client); // final avatars = Avatars(client); // final database = Databases(client); // final functions = Functions(client); // final health = Health(client); // final locale = Locale(client); // final storage = Storage(client); // final teams = Teams(client); // final users = Users(client);

if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) { print( "Environment variables are not set. Function cannot use Appwrite SDK.");

} else { client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(status: true); }

res.json({ 'areDevelopersAwesome': true, }); }```

Drake
6 May, 2023, 02:38

Did you create the variable?

conqueror
6 May, 2023, 04:59

after creating the variable its working fine,

conqueror
6 May, 2023, 05:02

trying to print payload but if i add print statement then function execution is failed saying An internal curl error has occurred within the executor! Error Msg: Operation timed out other wise its working fine, this is how using print print(req.payloads.toString());

Drake
6 May, 2023, 05:15

req doesn't have payloads. It's payload

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more