src/server.dart:115:25: Error: Method not found: 'main'.
user_code.main(context)
^^^^
src/server.dart:125:38: Error: Method not found: 'main'.
output = await user_code.main(context);
^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!```
Am unable to detect what the error is
Kindly assist if you can
#[SOLVED] dart & flutter - cloud function execution error from client and server
151 messages · Page 1 of 1 (latest)
Your function signiture is wrong with you function
Can I see your code? Did you start from a starter template?
It's trying to run the main function of your Appwrite function, but isn't finding the main function
I used the starter template @teal tundra
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);
client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject(projectId)
.setKey("API_KEY")
.setSelfSigned(status: true);
emptier();
setter();
// api from env var
apiToken = (req.variables['DAMMY_GONGOZ_API']);
// decode user request
userRequest = await jsonDecode(req.payload);
// decide which service
superResponse = await whichServiceExec();
{
res.json({
'Status': superResponse,
});
}
}```
👀 where did u get this?
this is very very old
sighs
And the function was created today and autogenerated by appwrite cli
ahhh yes
the CLI
can u do appwrite -v ?
what version is ur cli
maybe we missed something 🙃
2.0.2
!
sighs
what's the CMD for upgrade?
How'd u install?
I think via npm I guess
$ npm install -g appwrite-cli
run this again
i think should work
🤣
idk npm that well
I just did that
Still seeing version 2.0.2
arrhgggg
uninstall and try fresh install?
i don't remember the npm command 🤔 lemme go google 😄
Upgraded
Oh nice
IF it's still giving you an old function lmk
I'll go chase down a fix 😄
the new pattern seems trickier
So how do I decode a payload from client?
if it's JSON
body is already decoded
bodyRaw is a string
You can check a few examples here
does it mean that data sent from client is not encoded?
or do you mean that the data gotten by the function is automatically decoded when it gets to it?
```// The req object contains the request data
if (context.req.method == 'GET') {
// Send a response with the res object helpers
// res.send() dispatches a string back to the client
return context.res.send("Hello);
}
// res.json() is a handy helper for sending JSON
return context.res.json({
'motto': 'Build like a team of hundreds_',
'learn': 'https://appwrite.io/docs',
'connect': 'https://appwrite.io/discord',
'getInspired': 'https://builtwith.appwrite.io',
});```
@teal tundra
@proper fiber
@runic sandal
@real storm
@plucky jasper
thi may be inappropriate to tag you all, but I had no option
been unable to execute dart function after cli upgrade to latest...
You're using a template for an old appwrite version
That's the issue
I have upgraded i @proper fiber
to version 4
What's the updated code?
//
final client = Client();
client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject(projectId)
.setKey("API_KEY")
.setSelfSigned(status: true);
// You can log messages to the console
context.log('Hello, Logs!');
// If something goes wrong, log an error
context.error('Hello, Errors!');
emptier();
userRequest = context.req.query["numberToProcess"];
setter();
// api from env var
apiToken = (context.variables['DAMMY_GONGOZ_API']);
// decode user request
// decide which service
superResponse = await whichServiceExec();
///////////////////////////////////////////////////
// The `req` object contains the request data
if (context.req.method == 'GET') {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return context.res.send(superResponse);
}
// `res.json()` is a handy helper for sending JSON
return context.res.json({
'motto': 'Build like a team of hundreds_',
'learn': 'https://appwrite.io/docs',
'connect': 'https://appwrite.io/discord',
'getInspired': 'https://builtwith.appwrite.io',
'num': userRequest.toString()
});
}```
Client Code Was:
.createExecution(functionId: 'all_services', data: jsonEncode(data), );```
Changed To(after seeing new docs):
``` dynamic execution = await appWriteLogicExtender.functions.createExecution(
functionId: 'all_services',
body: json.encode(data),
async: false,
path: '/',
method: 'GET',
headers: {'X-Custom-Header': '123'});```
@proper fiber
And what's the error?
@proper fiber
Were you able to deploy the template code and execute it successfully?
Deployment was successful but execution wasn't.
Can't phantom how to use the new template yet.
So you did
appwrite init function
appwrite deploy function
Without modifying any code and the execution failed?
Please be patient and avoid spaming people on this server 🙂
It's like an HTTP request.
The client calls the Appwrite function, which sends an HTTP request, the request has a content type of json, but the body is by default still a string.
body is automatically decoded to be JSON
bodyRaw gives you the raw HTTP request body
still not clear
it's syntax is totally different from the former version that I had
or maybe if I could see a working client code that sends request and cloud function receiving it and making use of it before sending a response back to client
I have nto been abl to proceed for day now
@sly elbow So you did this already?
yes, execution is what is next currently
What do you mean?
the execution is throwing back error
Now that I am trying to deploy the function the old way, I am still getting errors.
Old function error during deployment after it failed, below is the logs:
src/server.dart:115:25: Error: Method not found: 'main'.
user_code.main(context)
^^^^
src/server.dart:125:38: Error: Method not found: 'main'.
output = await user_code.main(context);
^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!```
Sincerely, the developer experience with the updated dart function is not friendly to me.
I can't use either new way of deploying or the old way.
I am just delayed by 'no idea of what to do' for days.
👀 What is the code generated by the CLI?
It works for me
I think there's something wrong somewhere, I'm curious why it's not working, too.
What version of dart are you using?
Have you set the function entrypoint?
what error? and how are you executing the function?
and you're on appwrite cloud right?
dart 3.1.2
Yes
Besides, I used a a starter template code
am executing from Flutter app
below is the error
flutter: Error gotten from server: FormatException: Unexpected end of input (at character 1)
yes, appwrite cloud
@runic sandal
and what if you execute from the Appwrite console?
where do you see this error?
Not bad
But users won't be able to
Like myself
Flutter terminal
Catching error during execution
@runic sandal
What do you mean?
What do you mean?
While executing the function from my flutter app, that was the error that was displayed
I can execute function from console, but what about app users?
No console access for any of them
@runic sandal
This means the function is working fine and something may be wrong with your client code. what's your client code?
functionId: 'all_services',
data: jsonEncode(data),
);
execution.then((response) async {
}).catchError((error) {
});```
@runic sandal
even when I changed to the new syntax, it won't even send any communication to the cloud function
appwrite: ^11.0.0
is the only needed package for flutter front end?
please someone should help, I ave been on this for days
These are not the right params for version 11.0.0 of the SDK. Please also share more of your code and the stack trace of the error
I initialized appwrite in a class
Appwrite Class in client code
class AppWriteLogic extends GetxController {
// create account, function instance
Databases databases = Databases(client);
Functions functions = Functions(client);
Realtime realtime = Realtime(client);
late Account account;
// Functions functions = Functions(client);
@override
void onInit() async {
if (kDebugMode) {
print('appwrite controller inited');
}
super.onInit();
appwriteEndpointProjectID();
}
String walletBalanceCollectionID = "walletBalanceCollectionID";
String walletDatabaseID = "walletDatabaseID";
// pass in secret data
appwriteEndpointProjectID() {
client.setEndpoint(endpoint); // Your API Endpoint
client.setProject(projectId); // ID
client.setSelfSigned(status: false);
account = Account(client);
}
}
The use of Appwrite Init Class in client code
AppWriteLogic appWriteLogicExtender = AppWriteLogic();
The use of execution api in client code
dynamic data = {"name":userName, "class":userClass}
Future execution = appWriteLogicExtender.functions.createExecution(
functionId: 'automate_service_sender_2',
data: jsonEncode(data),
);
execution.then((response) async {
// do this
print(response);
}).catchError((error) {
print(error);
});
Dart function in server code
Future<dynamic> main(final context) async {
final client = Client();
client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject(projectID)
.setKey("API_KEY")
.setSelfSigned(status: true);
userRequest = jsonDecode(context.req.body);
context.res.json({"To": "Hi"});
context.res.send(userRequest.toString());
}
dart & flutter - cloud function execution error from client and server
@runic sandal @proper fiber @timid leaf
here is the code above
as i said, the params for functions.createExecution() is incorrect for version 11.0.0 of the flutter sdk
and please share details about the stacktrace of the error
for your function, you should not be calling both json and send. also, you need to return one of those
Receiver: Instance of 'Functions'
Tried calling: createExecution(data: "{\"numberToProcess\":\"phoneNum\",\"userMail\":\"[email protected]\",\"userID\":\"65383643cc5e7399b65b9\",\"totalServiceCharge\":\"120\",\"serciceTypeAndService\":\"MTN SME\",\"serviceQuantity\":\"500MB\",\"walletBalanceDocumentID\":\"phoneNum\",\"networkID\":\"1\",\"planID\":\"289\",\"serviceName\":\"Mobile Data\",\"customerAmount\":\"120\",\"currentUserBalance\":\"170\",\"previousWalletBalance\":\"50\",\"whatTypeOfTransaction\":\"Mobile Data\",\"supplierRate\":\"107.5\",\"transactionID\":\"unique()\"}", functionId: "all_services", headers: _Map len:1, method: "POST", path: "/", xasync: false)
Found: createExecution({required String functionId, String? data, bool? xasync}) => Future<Execution>```
the above error was getting using the new function...
```dynamic execution = await appWriteLogicExtender.functions.createExecution(
functionId: 'automate_service_sender_2',
data: jsonEncode(data),
xasync: false,
path: '/',
method: 'POST',
headers: {
'content-type': 'application/json',
},
);```
what is outputting this?
you have something wrong with your dependencies. maybe they're not actually downloaded/updated or something
Future execution = appWriteLogicExtender.functions.createExecution(
functionId: 'automate_service_sender_2',
data: jsonEncode(data),
);
execution.then((response) async {
// do this
print(response);
}).catchError((error) {
print(error);
});```
which should I use?
dart_appwrite: ^10.0.0
appwrite: ^11.0.0
appwrite_auth_kit:
why do you have dart_appwrite in your flutter app? you shouldn't be using that in your flutter app
you should be using 11.0.0 of the appwrite package
set a breakpoint at those 2 prints to see which one is being triggered.
I don't know where this text is coming from:
Error gotten from server
Is that in your function? somewhere else in your front end code?
Error gotten from server precedes the error from the server
I wrote it in frontend code
but I later removed others...
and then sent dummy request to server so I can get a predicted response also, but still resulted in error
@runic sandal
can't phantom the issues 😞😕
where, please share the code
did you fix the package problem?
I just removed it
And still face errors
@runic sandal
I meant I remove the remaining packages
And I'm using only the official appwrite: ^11.0.0 package 📦
so did you update the client code? what's your code now?
functionId: 'automate_service_sender_2',
data: jsonEncode(data),
xasync: false,
path: '/',
method: 'POST',
headers: {
'content-type': 'application/json',
},
);```
or how do I switch to former version, to avoid all this stress
Again, this is wrong and shouldn't even compile.
Try stopping your debugger, cleaning your flutter project, and restarting your IDE
The appWriteLogicExtender is an object of a class that initializes appwrite
works for other older function execution in same project
What do you suggest for me to do?
Cause when I even removed the initialization, it was still same, so I just left the object use
Did you do this? #1164988968262172722 message
I did flutter clean and then pub get, same thing
@runic sandal
Please hover over createExecution until the popup appears and share a screenshot of the popup and the code
Please share all the code
okay
the former syntax for getting variables was
req.variables['ENV_VAR'];
what is the new syntax?
@runic sandal
You haven't shared all the code or the screenshot....
I've figured getting response, so I didn't want to stress you.
What's left it how the cloud function can get my requests.
okay, I'll check that now.
and how will the function get my request?
What are you talking about? When you call functions.createExecution() the request gets sent to the function
Yes, how will the dart function get the request after execution is triggered
In the execution.responseBody. https://appwrite.io/docs/references/cloud/models/execution
}```
is this accurate?
My laptop isn't charged, waiting for power supply and by then you may be busy, so if I can get the clarity as soon as you can assist
Yes...
I'm closing this post now since the original problem is solved. Feel free to create a new post if you're still having trouble.
So how do I get and decode what the client said inside the dart function?
To be used by the cloud function during execution lifecycle?
okay, but before then, kindly check my last question before this
[SOLVED] dart & flutter - cloud function execution error from client and server
[closed] dart & flutter - cloud function execution error from client and server
I already told you #1164988968262172722 message
[SOLVED] dart & flutter - cloud function execution error from client and server
I'll check it right now