dart_frog icon indicating copy to clipboard operation
dart_frog copied to clipboard

feat: add global exception catching

Open wamynobe opened this issue 1 year ago • 6 comments

Description

Clearly describe what you are looking to add. The more context the better.

Requirements

  • [ ] Checklist of requirements to be fulfilled

Additional Context

Add any other context or screenshots about the feature request go here.

wamynobe avatar Jan 21 '24 05:01 wamynobe

Hi @wamynobe 👋 ! I'm curious to know if you have a proposal on how this should be done 👀, for example, do you have an API in mind?

alestiago avatar Feb 06 '24 12:02 alestiago

Hi @alestiago . I have some ideals.

void main() async {
  entrypoint.bootstrap(
    () async {
      final address = InternetAddress.tryParse('{{{host}}}') ?? InternetAddress.anyIPv6;
      final port = int.tryParse(Platform.environment['PORT'] ?? '{{{port}}}') ?? {{{port}}};{{#invokeCustomInit}}
      await entrypoint.init(address, port);{{/invokeCustomInit}}
      hotReload(() => createServer(address, port));
    }
  );
  
}

Can we add a bootstrap function in custom main file? This may help in some cases like using third-party SDK in order to log errors on my server. Then we can go like

void bootstrap(void Function() callback) async{
  runZonedGuarded(
    () => callback.call(),
    (error, stack) {
      // I want to log the error here
      log('Error: $error');
    },
  );
}

Or if you want to use SentrySDK for dart you can go like

void bootstrap(void Function() callback) async{
   await Sentry.init(
    (options) {
      options.dsn = 'https://[email protected]/example';
    },
    appRunner: callback,
  );
}

That's all! I'm new here so please forgive me if I've said anything wrong ^_^.

wamynobe avatar Feb 06 '24 16:02 wamynobe

I am trying to figure out how to use Mason and how to customize these bricks. I want to check my ideal but I have not found a way to custom dart_frog_dev_server yet.

wamynobe avatar Feb 06 '24 16:02 wamynobe

I checked dart_frog_dev_server brick but I have no ideal how to modify this file because of the line "// GENERATED CODE - DO NOT MODIFY BY HAND". I'm confused!

wamynobe avatar Feb 07 '24 14:02 wamynobe

@wamynobe thank you for taking an initiative here 💙 .

There is a CONTRIBUTING guide for updating Dart Frog CLI. There is no CONTRIBUTING guide for the bricks. I think we should have one. I may be able to provide one, however, you might have to bear with me, since I have other tasks with greater priority.

In terms of moving forward and adding global exception catching, it needs to be discussed with the team and evaluated. In the meantime, if you would like to work on a proof of concept, please do!

alestiago avatar Feb 07 '24 15:02 alestiago

@alestiago Thank you for the instructions. I can now edit the server.dart file and it works as I expected. Thanks for pointing out the contribute section in the cli. I honestly overlooked it when trying to modify bricks and bundles. Regarding this issue, after discussing with the team, if there is anything I can help with, please ask!

wamynobe avatar Feb 08 '24 07:02 wamynobe