Back

return context.res.send(bytes, 200, {'Content-Type': 'application/pdf'});

  • 1
  • Self Hosted
  • Functions
Shiba
5 Nov, 2023, 14:01

type 'Uint8List' is not a subtype of type 'String' of 'body' #0 main (package:generate_pdf/main.dart) <asynchronous suspension> #1 Future.any.onValue (dart:async/future.dart:615) <asynchronous suspension>

TypeScript
Future<dynamic> main(final context) async {
  final pdf = PDF();
  final order = FakeOrder();
  var fakeOrder = order.createFakeOrder();
  context.log(fakeOrder.toJson().toString());
  final Uint8List? bytes = await pdf.createAndSave(fakeOrder);

  if (bytes != null) {
    context.log('PDF created.');
    context.log(bytes);

    return context.res.send(bytes, 200, {'Content-Type': 'application/pdf'});
  }

  return context.error("Someting gone wrong");
}
TL;DR
The user is experiencing an error in their code when trying to send a `Uint8List` as a response in Dart. The error message states that `Uint8List` is not a subtype of `String`. The user needs to modify their code to convert the `Uint8List` to a `String` before sending the response. Alternatively, the user can also create a test case for sending a `Uint8List` as a response. They need to add a new case in their test file and expect a specific response, such as bytes or a value after UTF-8 encoding. This change will cause tests in other run
Drake
5 Nov, 2023, 22:13

Hmm it's a little hard to tell from what you provided. Can you figure out exactly what's throwing the error?

Shiba
5 Nov, 2023, 22:15

this line return context.res.send(bytes, 200, {'Content-Type': 'application/pdf'});

Drake
13 Nov, 2023, 20:56

Can you create a feature request for supporting non-strings?

Shiba
24 Nov, 2023, 06:59

I have created a pull-request

Meldiron
24 Nov, 2023, 11:32

Thanks for contributing ✨ Could you please also implement a test for it?

You will need to add a new case here: https://github.com/Shiba-Kar/open-runtimes/blob/main/tests/resources/functions/dart-3.0/lib/tests.dart#L118

In there, write a code that creates Uint8List, and sends it as response. To create it, you can read file, create it from string Hello World, or any other method that makes sense to you.

Next, you will need to add execution to a test script, which can be seen here: https://github.com/Shiba-Kar/open-runtimes/blob/main/tests/Base.php#L377-L388

In there you should expect specific response. Maybe bytes? Maybe multibytes? Maybe value after utf8 encoding? Not sure, do whatever feels natural to you and I will take a look during PR review.

Doing this will make tests in all other runtimes fail, but you can ignore that if you want to only focus on Dart. I can do the remaning languages, or we could ask other contributors. Just make sure they pass in Dart 3.0

Meldiron
24 Nov, 2023, 11:33

Please let me know if you are intereste in continuing this PR, and if you have any questions πŸ™

Shiba
24 Nov, 2023, 13:22

yes I am actively working on it

Shiba
24 Nov, 2023, 14:20

cmd RUNTIME='dart-3.0' TEST_CLASS='Base' ENTRYPOINT='tests.dart' sh tests.sh

Shiba
24 Nov, 2023, 14:20
TypeScript
What's Next?
  View summary of image vulnerabilities and recommendations β†’ docker scout quickview
Preparing for build ...
Resolving dependencies...
Got dependencies!
found user package open_runtimes_test
added user package as dependency to server.
Updated server import of user code
Building ...
Resolving dependencies...
+ archive 3.4.9
+ barcode 2.2.4
+ bidi 2.0.10
+ convert 3.1.1
+ crypto 3.0.3
+ dio 5.3.4
+ image 4.1.3
+ js 0.6.7
+ open_runtimes_test 1.0.0 from path /usr/local/build
+ path_parsing 1.0.1
+ pdf 3.10.6
+ petitparser 6.0.1
+ pointycastle 3.7.3
+ qr 3.0.1
+ vector_math 2.1.4
+ xml 6.4.2
Changed 16 dependencies!
Compiling ...
Info: Compiling with sound null safety.
Generated: /usr/local/server/server
Packing build ...
Build finished.
97f4a14c5554545bb8387b09d2e3cd25547dd94c7c7174564601f7c4fc7b34ff
Waiting for servers...
Running tests...
env: php: No such file or directory

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