David PHAM-VAN

Improve console error reporting

1 # Changelog 1 # Changelog
2 2
  3 +## 5.0.4
  4 +
  5 +- Improve console error reporting
  6 +
3 ## 5.0.3 7 ## 5.0.3
4 8
5 - Fix RichText annotations 9 - Fix RichText annotations
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # 3 #
4 Pod::Spec.new do |s| 4 Pod::Spec.new do |s|
5 s.name = 'printing' 5 s.name = 'printing'
6 - s.version = '0.0.1' 6 + s.version = '1.0.0'
7 s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers' 7 s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers'
8 s.description = <<-DESC 8 s.description = <<-DESC
9 Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers 9 Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
@@ -23,6 +23,7 @@ import 'dart:js_util'; @@ -23,6 +23,7 @@ import 'dart:js_util';
23 import 'dart:typed_data'; 23 import 'dart:typed_data';
24 import 'dart:ui'; 24 import 'dart:ui';
25 25
  26 +import 'package:flutter/foundation.dart';
26 import 'package:flutter/rendering.dart' show Rect; 27 import 'package:flutter/rendering.dart' show Rect;
27 import 'package:flutter_web_plugins/flutter_web_plugins.dart'; 28 import 'package:flutter_web_plugins/flutter_web_plugins.dart';
28 import 'package:image/image.dart' as im; 29 import 'package:image/image.dart' as im;
@@ -65,7 +66,30 @@ class PrintingPlugin extends PrintingPlatform { @@ -65,7 +66,30 @@ class PrintingPlugin extends PrintingPlatform {
65 PdfPageFormat format, 66 PdfPageFormat format,
66 bool dynamicLayout, 67 bool dynamicLayout,
67 ) async { 68 ) async {
68 - final result = await onLayout(format); 69 + late Uint8List result;
  70 + try {
  71 + result = await onLayout(format);
  72 + } catch (e, s) {
  73 + InformationCollector? collector;
  74 +
  75 + assert(() {
  76 + collector = () sync* {
  77 + yield StringProperty('PageFormat', format.toString());
  78 + };
  79 + return true;
  80 + }());
  81 +
  82 + FlutterError.reportError(FlutterErrorDetails(
  83 + exception: e,
  84 + stack: s,
  85 + stackFilter: (input) => input,
  86 + library: 'printing',
  87 + context: ErrorDescription('while generating a PDF'),
  88 + informationCollector: collector,
  89 + ));
  90 +
  91 + rethrow;
  92 + }
69 93
70 if (result.isEmpty) { 94 if (result.isEmpty) {
71 return false; 95 return false;
@@ -29,7 +29,7 @@ import 'raster.dart'; @@ -29,7 +29,7 @@ import 'raster.dart';
29 29
30 /// The interface that implementations of printing must implement. 30 /// The interface that implementations of printing must implement.
31 abstract class PrintingPlatform extends PlatformInterface { 31 abstract class PrintingPlatform extends PlatformInterface {
32 - /// Constructs a UrlLauncherPlatform. 32 + /// Constructs a PrintingPlatform.
33 PrintingPlatform() : super(token: _token); 33 PrintingPlatform() : super(token: _token);
34 34
35 static final Object _token = Object(); 35 static final Object _token = Object();
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 import 'dart:async'; 17 import 'dart:async';
18 import 'dart:typed_data'; 18 import 'dart:typed_data';
19 19
  20 +import 'package:flutter/foundation.dart';
20 import 'package:flutter/rendering.dart' show Rect; 21 import 'package:flutter/rendering.dart' show Rect;
21 import 'package:flutter/services.dart'; 22 import 'package:flutter/services.dart';
22 import 'package:pdf/pdf.dart'; 23 import 'package:pdf/pdf.dart';
@@ -60,7 +61,25 @@ class MethodChannelPrinting extends PrintingPlatform { @@ -60,7 +61,25 @@ class MethodChannelPrinting extends PrintingPlatform {
60 Uint8List bytes; 61 Uint8List bytes;
61 try { 62 try {
62 bytes = await job.onLayout!(format); 63 bytes = await job.onLayout!(format);
63 - } catch (e) { 64 + } catch (e, s) {
  65 + InformationCollector? collector;
  66 +
  67 + assert(() {
  68 + collector = () sync* {
  69 + yield StringProperty('PageFormat', format.toString());
  70 + };
  71 + return true;
  72 + }());
  73 +
  74 + FlutterError.reportError(FlutterErrorDetails(
  75 + exception: e,
  76 + stack: s,
  77 + stackFilter: (input) => input,
  78 + library: 'printing',
  79 + context: ErrorDescription('while generating a PDF'),
  80 + informationCollector: collector,
  81 + ));
  82 +
64 if (job.useFFI) { 83 if (job.useFFI) {
65 return setErrorFfi(job, e.toString()); 84 return setErrorFfi(job, e.toString());
66 } 85 }
@@ -2,6 +2,7 @@ import 'dart:async'; @@ -2,6 +2,7 @@ import 'dart:async';
2 import 'dart:math'; 2 import 'dart:math';
3 import 'dart:typed_data'; 3 import 'dart:typed_data';
4 4
  5 +import 'package:flutter/foundation.dart';
5 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
6 import 'package:pdf/pdf.dart'; 7 import 'package:pdf/pdf.dart';
7 import 'package:pdf/widgets.dart' as pw; 8 import 'package:pdf/widgets.dart' as pw;
@@ -140,13 +141,42 @@ class _PdfPreviewState extends State<PdfPreview> { @@ -140,13 +141,42 @@ class _PdfPreviewState extends State<PdfPreview> {
140 Uint8List _doc; 141 Uint8List _doc;
141 142
142 if (!info.canRaster) { 143 if (!info.canRaster) {
  144 + assert(() {
  145 + if (kIsWeb) {
  146 + FlutterError.reportError(FlutterErrorDetails(
  147 + exception: Exception(
  148 + 'Unable to find the `pdf.js` library.\nPlease follow the installation instructions at https://github.com/DavBfr/dart_pdf/tree/master/printing#installing'),
  149 + library: 'printing',
  150 + context: ErrorDescription('while rendering a PDF'),
  151 + ));
  152 + }
  153 +
  154 + return true;
  155 + }());
  156 +
143 return; 157 return;
144 } 158 }
145 159
146 try { 160 try {
147 _doc = await widget.build(computedPageFormat); 161 _doc = await widget.build(computedPageFormat);
148 - } catch (e) {  
149 - error = e; 162 + } catch (exception, stack) {
  163 + InformationCollector? collector;
  164 +
  165 + assert(() {
  166 + collector = () sync* {
  167 + yield StringProperty('PageFormat', computedPageFormat.toString());
  168 + };
  169 + return true;
  170 + }());
  171 +
  172 + FlutterError.reportError(FlutterErrorDetails(
  173 + exception: exception,
  174 + stack: stack,
  175 + library: 'printing',
  176 + context: ErrorDescription('while generating a PDF'),
  177 + informationCollector: collector,
  178 + ));
  179 + error = exception;
150 return; 180 return;
151 } 181 }
152 182
@@ -270,7 +300,6 @@ class _PdfPreviewState extends State<PdfPreview> { @@ -270,7 +300,6 @@ class _PdfPreviewState extends State<PdfPreview> {
270 if (error != null) { 300 if (error != null) {
271 var content = _showError(); 301 var content = _showError();
272 assert(() { 302 assert(() {
273 - print(error);  
274 content = ErrorWidget(error!); 303 content = ErrorWidget(error!);
275 return true; 304 return true;
276 }()); 305 }());
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # 3 #
4 Pod::Spec.new do |s| 4 Pod::Spec.new do |s|
5 s.name = 'printing' 5 s.name = 'printing'
6 - s.version = '0.0.1' 6 + s.version = '1.0.0'
7 s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers' 7 s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers'
8 s.description = <<-DESC 8 s.description = <<-DESC
9 Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers 9 Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
@@ -7,7 +7,7 @@ description: > @@ -7,7 +7,7 @@ description: >
7 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing 7 homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
8 repository: https://github.com/DavBfr/dart_pdf 8 repository: https://github.com/DavBfr/dart_pdf
9 issue_tracker: https://github.com/DavBfr/dart_pdf/issues 9 issue_tracker: https://github.com/DavBfr/dart_pdf/issues
10 -version: 5.0.3 10 +version: 5.0.4
11 11
12 environment: 12 environment:
13 sdk: ">=2.12.0-0 <3.0.0" 13 sdk: ">=2.12.0-0 <3.0.0"