catcher
catcher is flutter plugin which automatically catches error/exceptions and handle them. catcher offers mutliple way to handle errors. catcher is heavily inspired from acra: https://github.com/acra/acra catcher is solution for developers which want to get errors informations without using crashlytics or sentry product. it’s also great if you have your own backend where you’re storing application logs, so you can manipulate it anyway you want.
catcher supports android, ios and web platforms.
install
add this line to your pubspec.yaml:
dependencies:
catcher: ^0.3.15
then run this command:
$ flutter packages get
then add this import:
import 'package:catcher/catcher.dart';
platform support
catcher supports android, ios and web platforms. due to issues with web framework state and missing plugins, web implementation offers less features than mobile. here is features support table:
feature | android | ios | web |
---|---|---|---|
application data in report | ✔️ | ✔️ | ❌ |
console handler | ✔️ | ✔️ | ✔️ |
discord handler | ✔️ | ✔️ | ✔️ |
email auto handler | ✔️ | ✔️ | ❌ |
file handler | ✔️ | ✔️ | ❌ |
http handler | ✔️ | ✔️ | ✔️ |
sentry handler | ✔️ | ✔️ | ✔️ |
slack handler | ✔️ | ✔️ | ❌ |
toast handler | ✔️ | ✔️ | ✔️ |
crashlytics handler | ✔️ | ✔️ | ❌️ |
dialog report mode | ✔️ | ✔️ | ✔️ |
page report mode | ✔️ | ✔️ | ✔️ |
silent report mode | ✔️ | ✔️ | ✔️ |
explicit report mode map | ✔️ | ✔️ | ✔️ |
explicit report handler map | ✔️ | ✔️ | ✔️ |
error widget | ✔️ | ✔️ | ✔️ |
features supported may change in future, due to web framework and plugins intensive development.
basic example
basic example utilizes debug config with dialog report mode and console handler and release config with dialog report mode and email manual handler.
to start using catcher, you have to:
- create catcher configuration (you can use only debug config at start)
- create catcher instance and pass your root widget along with catcher configuration
- add navigator key to materialapp or cupertinoapp
here is complete example:
import 'package:flutter/material.dart';
import 'package:catcher/catcher.dart';
main() {
/// step 1. create catcher configuration.
/// debug configuration with dialog report mode and console handler. it will show dialog and once user accepts it, error will be shown /// in console.
catcheroptions debugoptions =
catcheroptions(dialogreportmode(), [consolehandler()]);
/// release configuration. same as above, but once user accepts dialog, user will be prompted to send email with crash to support.
catcheroptions releaseoptions = catcheroptions(dialogreportmode(), [
emailmanualhandler(["[email protected]"])
]);
/// step 2. pass your root widget (myapp) along with catcher configuration:
catcher(myapp(), debugconfig: debugoptions, releaseconfig: releaseoptions);
}
class myapp extends statefulwidget {
@override
_myappstate createstate() => _myappstate();
}
class _myappstate extends state<myapp> {
@override
void initstate() {
super.initstate();
}
@override
widget build(buildcontext context) {
return materialapp(
/// step 3. add navigator key from catcher. it will be used to navigate user to report page or to show dialog.
navigatorkey: catcher.navigatorkey,
home: scaffold(
appbar: appbar(
title: const text('plugin example app'),
),
body: childwidget()),
);
}
}
class childwidget extends statelesswidget {
@override
widget build(buildcontext context) {
return container(
child: flatbutton(
child: text("generate error"),
onpressed: () => generateerror()));
}
generateerror() async {
throw "test exception";
}
}
if you run this code you will see screen with “generate error” button on the screen.
after clicking on it, it will generate test exception, which will be handled by catcher. before catcher process exception to handler, it will
show dialog with information for user. this dialog is shown because we have used dialogreporthandler. once user confirms action in this dialog,
report will be send to console handler which will log to console error informations.
dialog with default confirmation message
i/flutter ( 7457): [2019-02-09 12:40:21.527271 | consolehandler | info] ============================== catcher log ==============================
i/flutter ( 7457): [2019-02-09 12:40:21.527742 | consolehandler | info] crash occured on 2019-02-09 12:40:20.424286
i/flutter ( 7457): [2019-02-09 12:40:21.527827 | consolehandler | info]
i/flutter ( 7457): [2019-02-09 12:40:21.527908 | consolehandler | info] ------- device info -------
i/flutter ( 7457): [2019-02-09 12:40:21.528233 | consolehandler | info] id: psr1.180720.061
i/flutter ( 7457): [2019-02-09 12:40:21.528337 | consolehandler | info] androidid: 726e4abc58dde277
i/flutter ( 7457): [2019-02-09 12:40:21.528431 | consolehandler | info] board: goldfish_x86
i/flutter ( 7457): [2019-02-09 12:40:21.528512 | consolehandler | info] bootloader: unknown
i/flutter ( 7457): [2019-02-09 12:40:21.528595 | consolehandler | info] brand: google
i/flutter ( 7457): [2019-02-09 12:40:21.528694 | consolehandler | info] device: generic_x86
i/flutter ( 7457): [2019-02-09 12:40:21.528774 | consolehandler | info] display: sdk_gphone_x86-userdebug 9 psr1.180720.061 5075414 dev-keys
i/flutter ( 7457): [2019-02-09 12:40:21.528855 | consolehandler | info] fingerprint: google/sdk_gphone_x86/generic_x86:9/psr1.180720.061/5075414:userdebug/dev-keys
i/flutter ( 7457): [2019-02-09 12:40:21.528939 | consolehandler | info] hardware: ranchu
i/flutter ( 7457): [2019-02-09 12:40:21.529023 | consolehandler | info] host: vped9.mtv.corp.google.com
i/flutter ( 7457): [2019-02-09 12:40:21.529813 | consolehandler | info] ispsychicaldevice: false
i/flutter ( 7457): [2019-02-09 12:40:21.530178 | consolehandler | info] manufacturer: google
i/flutter ( 7457): [2019-02-09 12:40:21.530345 | consolehandler | info] model: android sdk built for x86
i/flutter ( 7457): [2019-02-09 12:40:21.530443 | consolehandler | info] product: sdk_gphone_x86
i/flutter ( 7457): [2019-02-09 12:40:21.530610 | consolehandler | info] tags: dev-keys
i/flutter ( 7457): [2019-02-09 12:40:21.530713 | consolehandler | info] type: userdebug
i/flutter ( 7457): [2019-02-09 12:40:21.530825 | consolehandler | info] versionbaseos:
i/flutter ( 7457): [2019-02-09 12:40:21.530922 | consolehandler | info] versioncodename: rel
i/flutter ( 7457): [2019-02-09 12:40:21.531074 | consolehandler | info] versionincremental: 5075414
i/flutter ( 7457): [2019-02-09 12:40:21.531573 | consolehandler | info] versionpreviewsdk: 0
i/flutter ( 7457): [2019-02-09 12:40:21.531659 | consolehandler | info] versionrelase: 9
i/flutter ( 7457): [2019-02-09 12:40:21.531740 | consolehandler | info] versionsdk: 28
i/flutter ( 7457): [2019-02-09 12:40:21.531870 | consolehandler | info] versionsecuritypatch: 2018-08-05
i/flutter ( 7457): [2019-02-09 12:40:21.532002 | consolehandler | info]
i/flutter ( 7457): [2019-02-09 12:40:21.532078 | consolehandler | info] ------- app info -------
i/flutter ( 7457): [2019-02-09 12:40:21.532167 | consolehandler | info] version: 1.0
i/flutter ( 7457): [2019-02-09 12:40:21.532250 | consolehandler | info] appname: catcher_example
i/flutter ( 7457): [2019-02-09 12:40:21.532345 | consolehandler | info] buildnumber: 1
i/flutter ( 7457): [2019-02-09 12:40:21.532426 | consolehandler | info] packagename: com.jhomlala.catcherexample
i/flutter ( 7457): [2019-02-09 12:40:21.532667 | consolehandler | info]
i/flutter ( 7457): [2019-02-09 12:40:21.532944 | consolehandler | info] ---------- error ----------
i/flutter ( 7457): [2019-02-09 12:40:21.533096 | consolehandler | info] test exception
i/flutter ( 7457): [2019-02-09 12:40:21.533179 | consolehandler | info]
i/flutter ( 7457): [2019-02-09 12:40:21.533257 | consolehandler | info] ------- stack trace -------
i/flutter ( 7457): [2019-02-09 12:40:21.533695 | consolehandler | info] #0 childwidget.generateerror (package:catcher_example/file_example.dart:62:5)
i/flutter ( 7457): [2019-02-09 12:40:21.533799 | consolehandler | info] <asynchronous suspension>
i/flutter ( 7457): [2019-02-09 12:40:21.533879 | consolehandler | info] #1 childwidget.build.<anonymous closure> (package:catcher_example/file_example.dart:53:61)
i/flutter ( 7457): [2019-02-09 12:40:21.534149 | consolehandler | info] #2 _inkresponsestate._handletap (package:flutter/src/material/ink_well.dart:507:14)
i/flutter ( 7457): [2019-02-09 12:40:21.534230 | consolehandler | info] #3 _inkresponsestate.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
i/flutter ( 7457): [2019-02-09 12:40:21.534321 | consolehandler | info] #4 gesturerecognizer.invokecallback (package:flutter/src/gestures/recognizer.dart:102:24)
i/flutter ( 7457): [2019-02-09 12:40:21.534419 | consolehandler | info] #5 tapgesturerecognizer._checkup (package:flutter/src/gestures/tap.dart:242:9)
i/flutter ( 7457): [2019-02-09 12:40:21.534524 | consolehandler | info] #6 tapgesturerecognizer.handleprimarypointer (package:flutter/src/gestures/tap.dart:175:7)
i/flutter ( 7457): [2019-02-09 12:40:21.534608 | consolehandler | info] #7 primarypointergesturerecognizer.handleevent (package:flutter/src/gestures/recognizer.dart:315:9)
i/flutter ( 7457): [2019-02-09 12:40:21.534686 | consolehandler | info] #8 pointerrouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
i/flutter ( 7457): [2019-02-09 12:40:21.534765 | consolehandler | info] #9 pointerrouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
i/flutter ( 7457): [2019-02-09 12:40:21.534843 | consolehandler | info] #10 _widgetsflutterbinding&bindingbase&gesturebinding.handleevent (package:flutter/src/gestures/binding.dart:180:19)
i/flutter ( 7457): [2019-02-09 12:40:21.534973 | consolehandler | info] #11 _widgetsflutterbinding&bindingbase&gesturebinding.dispatchevent (package:flutter/src/gestures/binding.dart:158:22)
i/flutter ( 7457): [2019-02-09 12:40:21.535052 | consolehandler | info] #12 _widgetsflutterbinding&bindingbase&gesturebinding._handlepointerevent (package:flutter/src/gestures/binding.dart:138:7)
i/flutter ( 7457): [2019-02-09 12:40:21.535136 | consolehandler | info] #13 _widgetsflutterbinding&bindingbase&gesturebinding._flushpointereventqueue (package:flutter/src/gestures/binding.dart:101:7)
i/flutter ( 7457): [2019-02-09 12:40:21.535216 | consolehandler | info] #14 _widgetsflutterbinding&bindingbase&gesturebinding._handlepointerdatapacket (package:flutter/src/gestures/binding.dart:85:7)
i/flutter ( 7457): [2019-02-09 12:40:21.535600 | consolehandler | info] #15 _rootrununary (dart:async/zone.dart:1136:13)
i/flutter ( 7457): [2019-02-09 12:40:21.535753 | consolehandler | info] #16 _customzone.rununary (dart:async/zone.dart:1029:19)
i/flutter ( 7457): [2019-02-09 12:40:21.536008 | consolehandler | info] #17 _customzone.rununaryguarded (dart:async/zone.dart:931:7)
i/flutter ( 7457): [2019-02-09 12:40:21.536138 | consolehandler | info] #18 _invoke1 (dart:ui/hooks.dart:170:10)
i/flutter ( 7457): [2019-02-09 12:40:21.536271 | consolehandler | info] #19 _dispatchpointerdatapacket (dart:ui/hooks.dart:122:5)
i/flutter ( 7457): [2019-02-09 12:40:21.536375 | consolehandler | info]
i/flutter ( 7457): [2019-02-09 12:40:21.536539 | consolehandler | info] ======================================================================
console handler output
catcher usage
adding navigator key
in order to make work page report mode and dialog report mode, you must include navigator key. catcher plugin exposes key which must be included in your materialapp or widgetapp:
@override
widget build(buildcontext context) {
return materialapp(
//********************************************
navigatorkey: catcher.navigatorkey,
//********************************************
home: scaffold(
appbar: appbar(
title: const text('plugin example app'),
),
body: childwidget()),
);
}
you need to provide this key, because catcher needs context of navigator to show dialogs/pages. there is no need to include this navigator key if you won’t use page/dialog report mode.
you can also provide your own navigator key if need to. you can provide it with catcher constructor (see below). please check custom navigator key example to see basic example.
catcher configuration
catcher instance needs 1 required and 3 optional parameters.
- rootwidget (required) – instance of your root application widget
- debugconfig (optional) – config used when catcher detects that application runs in debug mode
- releaseconfig (optional) – config used when catcher detects that application runs in release mode
- profileconfig (optional) – config used when catcher detects that application runs in profile mode
- enablelogger (optional) – enable/disable internal catcher logs
- navigatorkey (optional) – provide optional navigator key from outside of catcher
main() {
catcheroptions debugoptions =
catcheroptions(dialogreportmode(), [consolehandler()]);
catcheroptions releaseoptions = catcheroptions(dialogreportmode(), [
emailmanualhandler(["[email protected]"])
]);
catcheroptions profileoptions = catcheroptions(
notificationreportmode(), [consolehandler(), toasthandler()],
handlertimeout: 10000, customparameters: {"example": "example_parameter"},);
catcher(myapp(), debugconfig: debugoptions, releaseconfig: releaseoptions, profileconfig: profileoptions, enablelogger: false, navigatorkey: navigatorkey);
}
catcheroptions parameters:
reportmode – describes how error report will be shown to user, see report modes to get more informations
handlers – list of handlers, which will process report, see handlers to get more informations
handlertimeout – timeout in milliseconds, this parameter describes max time of handling report by handler
customparameters – map of additional parameters that will be included in report (for example user id or user name)
report catched exception
catcher won’t process exceptions catched in try/catch block. you can send exception from try catch block to catcher:
try {
...
} catch (error,stacktrace) {
catcher.reportcheckederror(error, stacktrace);
}
localization
catcher allows to create localizations for report modes. to add localization support, you need setup
few things:
add navigatorkey in your materialapp:
navigatorkey: catcher.navigatorkey,
add flutter localizations delegates and locales in your materialapp:
localizationsdelegates: [
globalmateriallocalizations.delegate,
globalwidgetslocalizations.delegate,
],
supportedlocales: [
const locale('en', 'us'),
const locale('pl', 'pl'),
],
add localizationoptions in catcheroptions:
catcheroptions(
...
localizationoptions: [
localizationoptions("pl", notificationreportmodetitle: "my translation" ...),
localizationoptions("de", notificationreportmodetitle: "my translation" ...),
]
)
you can add translate for given parameters:
final string notificationreportmodetitle; // notification report mode title
final string notificationreportmodecontent; // notification report mode subtitle
final string dialogreportmodetitle; // dialog report mode title
final string dialogreportmodedescription; // dialog report mode description
final string dialogreportmodeaccept; // dialog report mode accept button
final string dialogreportmodecancel; // dialog report mode cancel button
final string pagereportmodetitle; // page report mode toolbar title
final string pagereportmodedescription; // page report mode description
final string pagereportmodeaccept; // page report mode accept button
final string pagereportmodecancel; // page report mode cancel button
if you want to override default english texts, just add simply localization options for “en” language.
there are build in support for languages:
- english
localizationoptions.builddefaultenglishoptions();
- chinese
localizationoptions.builddefaultchineseoptions();
- hindi
localizationoptions.builddefaulthindioptions();
- spanish
localizationoptions.builddefaultspanishoptions();
- malay
localizationoptions.builddefaultmalayoptions();
- russian
localizationoptions.builddefaultrussianoptions();
- portuguese
localizationoptions.builddefaultportugueseoptions();
- french
localizationoptions.builddefaultfrenchoptions();
- polish
localizationoptions.builddefaultpolishoptions();
- italian
localizationoptions.builddefaultitalianoptions();
- korean
localizationoptions.builddefaultkoreanoptions();
complete example:
import 'package:flutter/material.dart';
import 'package:catcher/catcher.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
main() {
catcheroptions debugoptions = catcheroptions(dialogreportmode(), [
consolehandler(),
httphandler(httprequesttype.post, uri.parse("https://httpstat.us/200"),
printlogs: true)
], localizationoptions: [
localizationoptions("pl",
notificationreportmodetitle: "wystąpił błąd aplikacji",
notificationreportmodecontent:
"naciśnij tutaj aby wysłać raport do zespołu wpsarcia",
dialogreportmodetitle: "błąd aplikacji",
dialogreportmodedescription:
"wystąpił niespodziewany błąd aplikacji. raport z błędem jest gotowy do wysłania do zespołu wsparcia. naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.",
dialogreportmodeaccept: "akceptuj",
dialogreportmodecancel: "odrzuć",
pagereportmodetitle: "błąd aplikacji",
pagereportmodedescription:
"wystąpił niespodziewany błąd aplikacji. raport z błędem jest gotowy do wysłania do zespołu wsparcia. naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.",
pagereportmodeaccept: "akceptuj",
pagereportmodecancel: "odrzuć")
]);
catcheroptions releaseoptions = catcheroptions(notificationreportmode(), [
emailmanualhandler(["[email protected]"])
]);
catcher(myapp(), debugconfig: debugoptions, releaseconfig: releaseoptions);
}
class myapp extends statefulwidget {
@override
_myappstate createstate() => _myappstate();
}
class _myappstate extends state<myapp> {
@override
void initstate() {
super.initstate();
}
@override
widget build(buildcontext context) {
return materialapp(
navigatorkey: catcher.navigatorkey,
localizationsdelegates: [
globalmateriallocalizations.delegate,
globalwidgetslocalizations.delegate,
],
supportedlocales: [
const locale('en', 'us'),
const locale('pl', 'pl'),
],
home: scaffold(
appbar: appbar(
title: const text('plugin example app'),
),
body: childwidget()),
);
}
}
class childwidget extends statelesswidget {
@override
widget build(buildcontext context) {
return container(
child: flatbutton(
child: text("generate error"), onpressed: () => generateerror()));
}
generateerror() async {
throw "test exception";
}
}
report modes
report mode is the process of gathering user permission to handle error. user can accept or deny permission to handle error. there are 4 types of report mode:
silent report mode
silent report mode is default report mode. this report mode doesn’t ask user for permission to handle crash logs. it will push logs automatically to handlers.
reportmode reportmode = silentreportmode();
notification report mode
notification report mode has been removed because of incompatbility with firebase. please check local_notifications_example to re-add local notificaitons to your app.
dialog report mode
dialog report mode shows dialog with information about error. dialog has title, description and 2 buttons: accept and cancel. once user clicks on accept button, report will be pushed to handlers.
reportmode reportmode = dialogreportmode();
see localization options to change default texts.
dialog report mode
page report mode
page report mode shows new page with information about error. page has title, description, stack trace view and 2 buttons: accept and cancel. once user clicks on accept button, report will be pushed to handlers.
reportmode reportmode = pagereportmode(showstacktrace: false);
page report mode can be configured with optional parameters:
showstacktrace (optional) – enables/disables stack trace view
see localization options to change default texts.
page report mode
handlers
handlers are an last point in error processing flow. they are doing specific task with error report, for example logging report to console.
console handler
console handler is the default and basic handler. it show crash log in console. console logger allows you to parametrize log output:
consolehandler(
enableapplicationparameters: true,
enabledeviceparameters: true,
enablecustomparameters: true,
enablestacktrace: true)
- enableapplicationparameters (optional) – display in log section with application data:
i/flutter ( 4820): ------- app info -------
i/flutter ( 4820): version: 1.0
i/flutter ( 4820): appname: catcher_example
i/flutter ( 4820): buildnumber: 1
i/flutter ( 4820): packagename: com.jhomlala.catcherexample
i/flutter ( 4820):
- enabledeviceparameters (optional) – display in log section with device data (it will show android/ios data):
i/flutter ( 4820): ------- device info -------
i/flutter ( 4820): id: psr1.180720.061
i/flutter ( 4820): androidid: fd97a76448e87410
i/flutter ( 4820): board: goldfish_x86
i/flutter ( 4820): bootloader: unknown
i/flutter ( 4820): brand: google
i/flutter ( 4820): device: generic_x86
i/flutter ( 4820): display: sdk_gphone_x86-userdebug 9 psr1.180720.061 5075414 dev-keys
i/flutter ( 4820): fingerprint: google/sdk_gphone_x86/generic_x86:9/psr1.180720.061/5075414:userdebug/dev-keys
i/flutter ( 4820): hardware: ranchu
i/flutter ( 4820): host: vped9.mtv.corp.google.com
i/flutter ( 4820): ispsychicaldevice: false
i/flutter ( 4820): manufacturer: google
i/flutter ( 4820): model: android sdk built for x86
i/flutter ( 4820): product: sdk_gphone_x86
i/flutter ( 4820): tags: dev-keys
i/flutter ( 4820): type: userdebug
i/flutter ( 4820): versionbaseos:
i/flutter ( 4820): versioncodename: rel
i/flutter ( 4820): versionincremental: 5075414
i/flutter ( 4820): versionpreviewsdk: 0
i/flutter ( 4820): versionrelase: 9
i/flutter ( 4820): versionsdk: 28
i/flutter ( 4820): versionsecuritypatch: 2018-08-05
- enablecustomparameters (optional) – display in log section with custom parameters passed to catcher constructor
- enablestacktrace (optional) – display in log section with stack trace:
i/flutter ( 5073): ------- stack trace -------
i/flutter ( 5073): #0 _myappstate.generateerror (package:catcher_example/main.dart:38:5)
i/flutter ( 5073): <asynchronous suspension>
i/flutter ( 5073): #1 _myappstate.build.<anonymous closure> (package:catcher_example/main.dart:31:69)
i/flutter ( 5073): #2 _inkresponsestate._handletap (package:flutter/src/material/ink_well.dart:507:14)
i/flutter ( 5073): #3 _inkresponsestate.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
i/flutter ( 5073): #4 gesturerecognizer.invokecallback (package:flutter/src/gestures/recognizer.dart:102:24)
i/flutter ( 5073): #5 tapgesturerecognizer._checkup (package:flutter/src/gestures/tap.dart:242:9)
i/flutter ( 5073): #6 tapgesturerecognizer.handleprimarypointer (package:flutter/src/gestures/tap.dart:175:7)
i/flutter ( 5073): #7 primarypointergesturerecognizer.handleevent (package:flutter/src/gestures/recognizer.dart:315:9)
i/flutter ( 5073): #8 pointerrouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
i/flutter ( 5073): #9 pointerrouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
i/flutter ( 5073): #10 _widgetsflutterbinding&bindingbase&gesturebinding.handleevent (package:flutter
email manual handler
email manual handler can be used to send email manually by user. it opens default email application with prepared email.
emailmanualhandler(
["[email protected]", "[email protected]"],
enabledeviceparameters: true,
enablestacktrace: true,
enablecustomparameters: true,
enableapplicationparameters: true,
sendhtml: true,
emailtitle: "sample title",
emailheader: "sample header",
printlogs: true)
email manual handler parameters:
- recipients (required) – list of email addresses of recipients
- enabledeviceparameters (optional) – see console handler description
- enablestacktrace (optional) – see console handler description
- enablecustomparameters (optional) – see console handler description
- enableapplicationparameters (optional) – see console handler description
- sendhtml (optional) – enable/disable html email formatting
- emailtitle (optional) – set custom email title
- emailheader (optional) – set additional email text header
- printlogs (optional) – enable/disable debug logs
email auto handler
email handler can be used to send automatically email with error reports. email handler has multiple configuration parameters. few of them are required, other are optional. these parameters are required:
emailautohandler("smtp.gmail.com", 587, "[email protected]", "catcher",
"fakepassword", ["[email protected]"])
we need to setup email smtp server, email account and recipient. currently, only gmail was tested and worked. you can try use other email providers, but there can be errors.
list of all parameters:
- smtphost (required) – host address of your email, for example host for gmail is smtp.gmail.com
- smtpport (required) – smtp port of your email, for example port for gmail is 587
- senderemail (required) – email from which catcher will send email (it will be sender of error emails)
- sendername (required) – name of sender email
- senderpassword (required) – password for sender email
- recipients (required) – list which contains recipient emails
- enablessl (optional) – if your email provider supports ssl, you can enable this option
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablestacktrace (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- emailtitle (optional) – custom title of report email, if not set then title will be:
handled error: >> [error name] <<
- emailheader (optional)- custom header message before report data
- sendhtml (optional) – enable/disable html data in your email, if enabled then html will be sent and your report will look much better
- printlog (optional) – enable/disable debug logs
example email:
http handler
http handler provides feature for sending report to external server. data will be encoded in json and sent to specified server. currently only post request can be send. minimal example:
httphandler(httprequesttype.post, uri.parse("http://logs.server.com")
all parameters list:
- requesttype (required) – type of request, currently only post is supported
- endpointuri (required) – uri address of server
- headers (optional) – map of additional headers that can be send in http request
- requesttimeout (optional) – request time in milliseconds
- printlogs (optional) – show debug logs
you can try using example backend server which handles logs. it’s written in java 8 and spring framework and uses material design.
you can find code of backend server here: https://github.com/jhomlala/catcher/tree/master/backend
note: remeber to add internet permission in android manifest:
<uses-permission android:name="android.permission.internet"/>
file handler
file handler allows to store logs in file. minimal example:
main() {
string path = "/storage/emulated/0/log.txt";
catcheroptions debugoptions = catcheroptions(
dialogreportmode(), [filehandler(file(path), printlogs: true)]);
catcheroptions releaseoptions =
catcheroptions(dialogreportmode(), [filehandler(file(path))]);
catcher(myapp(), debugconfig: debugoptions, releaseconfig: releaseoptions);
}
all parameters list:
- file (required) – the file where you want to store your logs
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablestacktrace (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- printlogs (optional) – enable/disable debug logs
example of logging to file in external directory: https://github.com/jhomlala/catcher/blob/master/example/lib/file_example.dart
toast handler
toast handler allows to show short message in toast. minimal example:
all parameters list:
- gravity (optional) – location of the toast on screen top/middle/bottom
- length (optional) – length of toast: long or short
- backgroundcolor (optional) – background color of toast
- textcolor (optional) – text color of toast
- fontsize (optional) – text size
- custommessage (optional) – custom message for toast, if not set then “error occured: error” will be displayed.
sentry handler
sentry handler allows to send handled errors to sentry.io. before using sentry handler, you need to create your project in
sentry.io page and then copy dsn link. example:
main() {
catcheroptions debugoptions = catcheroptions(
dialogreportmode(), [sentryhandler(sentryclient("your_dsn_here"))]);
catcheroptions releaseoptions = catcheroptions(notificationreportmode(), [
emailmanualhandler(["[email protected]"])
]);
catcher(myapp(), debugconfig: debugoptions, releaseconfig: releaseoptions);
}
all parameters list:
- sentryclient – sentry client instance
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- printlogs (optional) – enable/disable debug logs
slack handler
slack handler allows to send messages to your slack workspace. you can specify destination
of your message and format. you need to register webhook in your workspace to make this handler
works: https://api.slack.com/incoming-webhooks.
main() {
catcheroptions debugoptions = catcheroptions(silentreportmode(), [
slackhandler(
"<web_hook_url>",
"#catcher",
username: "catchertest",
iconemoji: ":thinking_face:",
enabledeviceparameters: true,
enableapplicationparameters: true,
enablecustomparameters: true,
enablestacktrace: true,
printlogs: true),
]);
catcher(myapp(), debugconfig: debugoptions);
}
all parameters list:
- webhookurl (required) – url of your webhook
- channel (required) – your channel name (i.e. #catcher)
- username (optional) – name of the integration bot
- iconemoji (optional) – avatar of the integration bot
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- enablestacktrace (optional) – please look in console handler description
- printlogs (optional) – enable/disable debug logs
discord handler
discord handler allows to send messages to your discord workspace. you need to register webhook in your server to make this handler
works: https://support.discordapp.com/hc/en-us/articles/228383668-intro-to-webhooks.
main() {
catcheroptions debugoptions = catcheroptions(silentreportmode(), [
discordhandler(
"<web_hook_url>",
enabledeviceparameters: true,
enableapplicationparameters: true,
enablecustomparameters: true,
enablestacktrace: true,
printlogs: true),
]);
catcher(myapp(), debugconfig: debugoptions);
}
all parameters list:
- webhookurl (required) – url of your webhook
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- enablestacktrace (optional) – please look in console handler description
- printlogs (optional) – enable/disable debug logs
crashlytics handler
crashlytics handler allows to send crash reports to firebase service. you need to setup your project
with firebase libraries first. follow instructions from here:
https://pub.dev/packages/firebase_crashlytics and https://firebase.google.com/docs/crashlytics/get-started
main() {
catcheroptions debugoptions = catcheroptions(silentreportmode(), [
crashlyticshandler(
enabledeviceparameters: true,
enableapplicationparameters: true,
enablecustomparameters: true,
printlogs: true),
]);
catcher(myapp(), debugconfig: debugoptions);
}
all parameters list:
- enabledeviceparameters (optional) – please look in console handler description
- enableapplicationparameters (optional) – please look in console handler description
- enablecustomparameters (optional) – please look in console handler description
- printlogs (optional) – enable/disable debug logs
explicit exception report handler map
explicit exception report handler map allows you to setup report handler for specific exception. for example if you want to setup console handler for formatexception, you can write:
var explicitmap = {"formatexception": consolehandler()};
catcheroptions debugoptions = catcheroptions(
dialogreportmode(),
[
consolehandler(),
httphandler(httprequesttype.post, uri.parse("https://httpstat.us/200"),
printlogs: true)
],
explicitexceptionhandlersmap: explicitmap);
now if formatexception
will be catched, then console handler will be used. warning: if you setup explicit exception map for specific exception, then only this handler will be used for this exception!
explicit exception report mode map
same as explicit report handler map, but it’s for report mode. let’s say you want to use specific report mode for some exception:
var explicitreportmodesmap = {"formatexception": notificationreportmode()};
catcheroptions debugoptions = catcheroptions(
dialogreportmode(),
[
consolehandler(),
httphandler(httprequesttype.post, uri.parse("https://httpstat.us/200"),
printlogs: true)
],
explicitexceptionreportmodesmap: explicitreportmodesmap,);
when formatexception
will be catched, then notificationreportmode will be used. for other exceptions, catcher will use dialogreportmode.
error widget
you can add error widget which will replace red screen of death. to add this into your app, see code below:
@override
widget build(buildcontext context) {
return materialapp(
navigatorkey: catcher.navigatorkey,
//********************************************
builder: (buildcontext context, widget widget) {
catcher.adddefaulterrorwidget(
showstacktrace: true,
title: "custom error title",
description: "custom error description",
maxwidthforsmallmode: 150);
return widget;
},
//********************************************
home: scaffold(
appbar: appbar(
title: const text('plugin example app'),
),
body: childwidget()),
);
}
you need to add in your materialapp or cupertinoapp builder method with catcher.adddefaulterrorwidget()
. this will add error handler for each widget in your app.
you can provide optional parameters:
- showstacktrace – show/hide stacktrace
- title – custom title for error widget
- description – custom description for error widget
- maxwidthforsmallmode – max width for “small” mode, default is 150
error widget will replace your widget if he fails to render. if width of widget is less than maxwidthforsmallmode then “small” mode will be enabled, which will show only error icon
with error widget | without error widget |
current config
you can get currently used config by using:
catcheroptions options = catcher.getcurrentconfig();
this can be used for example to change custom parameters in runtime.
test exception
send test exception:
catcher.sendtestexception();
Comments are closed.