Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Rendering Errors #1090

Open
ganeshh123 opened this issue Nov 5, 2023 · 4 comments
Open

Catch Rendering Errors #1090

ganeshh123 opened this issue Nov 5, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@ganeshh123
Copy link

Hello, thanks a lot for the time you've put into this package. I was wondering if it would be possible to know and catch if any errors occur during rendering.

Use case

I'm rendering content that comes in from a source where I have no control. Sometimes there are SVG tags that do not have dimensions properly specified, which causes the SVG library to thrown an exeption and crash the whole application.

For example:

<center><svg height="159.37501525878906" style="
        width:661.0667114257812px;
        height:159.37501525878906px;
        background: #FFF;
        fill: none;
" width="661.0667114257812" x="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0"> <svg class="role-diagram-draw-area" xmlns="http://www.w3.org/2000/svg"><g class="shapes-region" style="stroke: black; fill: none;"><g class="arrow-line"><path class="connection real" d="  M68,103 L578.93,101.42" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 4; fill: none; fill-opacity: 1;"></path><g fill="#000" stroke="none" style="stroke: none; fill: rgb(0, 0, 0); stroke-width: 4;" transform="matrix(-0.9999950652018582,0.0031415874858815116,-0.0031415874858815116,-0.9999950652018582,584.9332885742189,101.39999389648436)"><path d=" M16.97,-8.15 L0,0 L16.97,8.15 Z"></path></g></g><g class="arrow-line"><path class="connection real" d="  M326.43,91.4 L326.5,113" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 1; fill: none; fill-opacity: 1;"></path></g><g class="arrow-line"><path class="connection real" d="  M229.93,91.4 L230,113" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 1; fill: none; fill-opacity: 1;"></path></g><g class="arrow-line"><path class="connection real" d="  M139.93,91.4 L140,113" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 1; fill: none; fill-opacity: 1;"></path></g><g class="arrow-line"><path class="connection real" d="  M415.43,91.4 L415.5,113" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 1; fill: none; fill-opacity: 1;"></path></g><g class="arrow-line"><path class="connection real" d="  M502.43,91.9 L502.5,113.5" stroke-dasharray="" style="stroke: rgb(0, 0, 0); stroke-width: 1; fill: none; fill-opacity: 1;"></path></g><g class="arrow-line"><path class="connection real" d="  M200.1,21.61 L442.6,21.61" stroke-dasharray="" style="stroke: rgb(208, 2, 27); stroke-opacity: 1; stroke-width: 1; fill: none; fill-opacity: 1;"></path><g stroke="rgb(208,2,27)" stroke-opacity="1" style="stroke: rgb(208, 2, 27); stroke-width: 1;" transform="matrix(-1,1.2246467991473532e-16,-1.2246467991473532e-16,-1,444.59999084472656,21.608329772949215)"><path d=" M10.93,-3.29 Q4.96,-0.45 0,0 Q4.96,0.45 10.93,3.29"></path></g></g><g></g></g><g></g><g></g><g></g></svg> <svg height="158.30833435058594" style="width:660.0000610351562px;height:158.30833435058594px;font-family:Asana-Math, Asana;background:#FFF;" width="660.0000610351562" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><g><g><g transform="matrix(1,0,0,1,319.0333251953125,141.94335571289062)"><path d="M263 689C108 689 29 566 29 324C29 207 50 106 85 57C120 8 176 -20 238 -20C389 -20 465 110 465 366C465 585 400 689 263 689ZM245 654C342 654 381 556 381 316C381 103 343 15 251 15C154 15 113 116 113 360C113 571 150 654 245 654Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g></g></g><g><g><g><g transform="matrix(1,0,0,1,213.0333251953125,141.94335571289062)"><path d="M555 243L555 299L51 299L51 243Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g><g><g transform="matrix(1,0,0,1,230.83331298828125,141.94335571289062)"><path d="M459 253C459 366 378 446 264 446C216 446 180 443 127 396L127 605L432 604L432 689L75 690L75 322L95 316C142 363 169 377 218 377C314 377 374 309 374 201C374 90 310 25 201 25C147 25 97 43 83 69L37 151L13 137C36 80 48 48 62 4C90 -11 130 -20 173 -20C301 -20 459 89 459 253Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g></g></g><g><g><g><g transform="matrix(1,0,0,1,116.5333251953125,141.94335571289062)"><path d="M555 243L555 299L51 299L51 243Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g><g><g transform="matrix(1,0,0,1,134.33331298828125,141.94335571289062)"><path d="M418 -3L418 27L366 30C311 33 301 44 301 96L301 700L60 598L67 548L217 614L217 96C217 44 206 33 152 30L96 27L96 -3C250 0 250 0 261 0C292 0 402 -3 418 -3ZM762 689C607 689 528 566 528 324C528 207 549 106 584 57C619 8 675 -20 737 -20C888 -20 964 110 964 366C964 585 899 689 762 689ZM744 654C841 654 880 556 880 316C880 103 842 15 750 15C653 15 612 116 612 360C612 571 649 654 744 654Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g></g></g><g><g><g><g transform="matrix(1,0,0,1,408.03338623046875,141.94335571289062)"><path d="M459 253C459 366 378 446 264 446C216 446 180 443 127 396L127 605L432 604L432 689L75 690L75 322L95 316C142 363 169 377 218 377C314 377 374 309 374 201C374 90 310 25 201 25C147 25 97 43 83 69L37 151L13 137C36 80 48 48 62 4C90 -11 130 -20 173 -20C301 -20 459 89 459 253Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g></g></g><g><g><g><g transform="matrix(1,0,0,1,488.03338623046875,141.94335571289062)"><path d="M418 -3L418 27L366 30C311 33 301 44 301 96L301 700L60 598L67 548L217 614L217 96C217 44 206 33 152 30L96 27L96 -3C250 0 250 0 261 0C292 0 402 -3 418 -3ZM762 689C607 689 528 566 528 324C528 207 549 106 584 57C619 8 675 -20 737 -20C888 -20 964 110 964 366C964 585 899 689 762 689ZM744 654C841 654 880 556 880 316C880 103 842 15 750 15C653 15 612 116 612 360C612 571 649 654 744 654Z" fill="rgb(74,144,226)" fill-opacity="1" stroke="rgb(74,144,226)" stroke-opacity="1" stroke-width="8" transform="matrix(0.02941,0,0,-0.02941,0,0)"></path></g></g></g></g><g><g><g><g transform="matrix(1,0,0,1,140.125,53.033355712890625)"><path d="M582 103L237 692L75 692L70 664L105 662C150 660 184 615 185 606L92 102C80 40 74 32 38 28L7 25L2 -3L113 0C125 0 126 0 223 -3L228 25L186 28C146 31 137 39 137 72C137 80 138 91 140 102L220 566L558 -11L608 -11L702 542C723 655 725 659 762 662L799 664L802 691L589 692L584 664L631 662C657 661 667 654 667 638C667 631 584 116 582 103ZM1269 473L1262 482L1194 465L1184 414C1169 336 1144 268 1113 221C1054 130 976 59 936 59C928 59 923 68 923 85C923 99 925 112 930 137L987 408C990 424 992 438 992 451C992 470 983 482 969 482C949 482 911 461 837 408L809 388L816 368L848 389C876 407 887 412 896 412C905 412 913 403 913 392C913 388 912 378 911 374L848 77C846 68 844 44 844 30C844 7 859 -11 879 -11C942 -11 1063 101 1147 239L1110 97C1103 73 1099 46 1099 31C1099 6 1110 -9 1129 -9C1155 -9 1191 12 1289 85L1279 103L1253 86C1229 70 1203 59 1192 59C1184 59 1179 66 1179 76C1179 112 1254 416 1269 473ZM2062 103L2036 86C2007 67 1985 56 1975 56C1968 56 1962 65 1962 76C1962 86 1964 95 1969 116L2044 413C2048 430 2051 446 2051 454C2051 471 2041 482 2025 482C1996 482 1958 464 1897 421C1834 376 1799 341 1750 272L1780 409C1784 429 1787 444 1787 451C1787 470 1777 482 1761 482C1731 482 1685 460 1630 418C1586 384 1566 363 1501 275L1534 408C1538 424 1540 439 1540 451C1540 470 1531 482 1517 482C1496 482 1458 461 1384 408L1356 388L1363 368C1400 391 1435 414 1442 414C1453 414 1460 404 1460 389C1460 338 1419 145 1378 2L1381 -9L1449 6L1471 108C1495 219 1522 278 1577 338C1619 384 1664 414 1692 414C1699 414 1703 406 1703 393C1703 358 1681 244 1640 69L1624 2L1629 -9L1698 6L1719 113C1735 194 1769 269 1813 318C1868 379 1918 414 1950 414C1958 414 1963 405 1963 389C1963 365 1960 351 1938 264C1898 105 1882 84 1882 31C1882 6 1893 -9 1912 -9C1938 -9 1974 12 2072 85ZM2344 722L2332 733C2280 707 2244 698 2172 691L2168 670L2216 670C2240 670 2250 663 2250 646C2250 639 2249 628 2248 622L2147 71C2146 68 2146 64 2146 61C2146 22 2194 -11 2249 -11C2286 -11 2337 8 2380 39C2476 107 2542 244 2542 376C2542 414 2533 453 2521 468C2514 477 2501 482 2486 482C2462 482 2432 474 2404 460C2353 433 2320 403 2258 324ZM2431 424C2457 424 2470 401 2470 352C2470 288 2449 202 2419 137C2386 68 2346 36 2292 36C2246 36 2221 59 2221 101C2221 135 2236 276 2317 361C2350 395 2402 424 2431 424ZM2899 111L2875 94C2822 56 2774 36 2738 36C2691 36 2662 73 2662 133C2662 158 2665 185 2670 214C2687 218 2796 248 2821 259C2906 296 2945 342 2945 404C2945 451 2911 482 2861 482C2793 496 2683 423 2646 349C2616 299 2586 180 2586 113C2586 35 2630 -11 2702 -11C2759 -11 2815 17 2907 92ZM2684 274C2701 343 2721 386 2750 412C2768 428 2799 440 2823 440C2852 440 2871 420 2871 388C2871 344 2836 297 2784 272C2756 258 2720 247 2675 237ZM3327 365C3330 403 3335 435 3343 476C3332 481 3328 482 3323 482C3292 482 3261 458 3225 407C3186 351 3147 291 3131 256L3163 408C3167 425 3169 438 3169 450C3169 470 3161 482 3146 482C3125 482 3087 461 3013 408L2985 388L2992 368L3024 389C3052 407 3063 412 3072 412C3082 412 3089 403 3089 390C3089 332 3046 126 3006 -2L3016 -9C3031 -4 3047 -1 3070 4L3083 6L3109 126C3127 209 3150 262 3194 319C3228 363 3255 384 3277 384C3292 384 3302 379 3313 365ZM3378 148C3373 97 3367 62 3356 16C3394 -2 3428 -11 3463 -11C3512 -11 3558 7 3609 47C3660 87 3681 124 3681 174C3681 228 3649 257 3575 271L3532 279C3472 290 3453 307 3453 348C3453 401 3498 442 3555 442C3596 442 3634 424 3650 397L3650 342L3673 342C3677 377 3681 404 3692 455C3653 474 3625 482 3592 482C3540 482 3479 452 3431 404C3405 377 3394 352 3394 316C3394 260 3425 228 3491 215L3554 203C3598 195 3614 177 3614 138C3614 73 3568 29 3497 29C3462 29 3431 40 3403 64L3403 148ZM4259 482C4192 482 4039 419 4039 259C4039 182 4084 136 4161 136C4169 136 4180 136 4191 137L4150 99C4134 84 4123 66 4123 52C4123 42 4130 31 4144 19C4075 -4 3947 -48 3947 -159C3947 -230 4017 -276 4126 -276C4255 -276 4368 -204 4368 -121C4368 -85 4347 -49 4304 -14L4244 35C4210 62 4197 81 4197 100C4197 114 4212 128 4224 146C4322 170 4393 253 4393 342C4393 357 4390 376 4389 380C4406 378 4414 378 4423 378C4440 378 4450 379 4473 382L4482 427L4479 433C4451 426 4431 424 4377 424C4377 425 4353 482 4259 482ZM4160 1L4237 -58C4283 -94 4302 -121 4302 -154C4302 -206 4233 -248 4150 -248C4068 -248 4011 -206 4011 -145C4011 -43 4121 -11 4160 1ZM4234 448C4292 448 4321 412 4321 341C4321 238 4273 168 4203 168C4142 168 4110 209 4110 288C4110 383 4161 448 4234 448ZM4811 111L4787 94C4734 56 4686 36 4650 36C4603 36 4574 73 4574 133C4574 158 4577 185 4582 214C4599 218 4708 248 4733 259C4818 296 4857 342 4857 404C4857 451 4823 482 4773 482C4705 496 4595 423 4558 349C4528 299 4498 180 4498 113C4498 35 4542 -11 4614 -11C4671 -11 4727 17 4819 92ZM4596 274C4613 343 4633 386 4662 412C4680 428 4711 440 4735 440C4764 440 4783 420 4783 388C4783 344 4748 297 4696 272C4668 258 4632 247 4587 237ZM4996 390L4940 107C4939 99 4927 61 4927 31C4927 6 4938 -9 4957 -9C4992 -9 5027 11 5105 74L5136 99L5126 117L5081 86C5052 66 5032 56 5021 56C5012 56 5007 64 5007 76C5007 102 5021 183 5050 328L5063 390L5170 390L5181 440C5143 436 5109 434 5071 434C5087 528 5098 577 5116 631L5105 646C5085 634 5058 622 5027 610L5002 440C4958 419 4932 408 4914 403L4912 390ZM5703 722L5691 733C5639 707 5603 698 5531 691L5527 670L5575 670C5599 670 5609 663 5609 648C5609 645 5609 640 5606 622C5595 567 5522 182 5507 132C5494 82 5488 52 5488 31C5488 6 5499 -9 5518 -9C5544 -9 5580 12 5678 85L5668 103L5642 86C5613 67 5591 56 5581 56C5574 56 5568 66 5568 76C5568 82 5569 89 5572 104ZM6000 204L5971 77C5967 60 5965 42 5965 26C5965 4 5974 -9 5989 -9C6012 -9 6053 17 6135 85L6128 106C6104 86 6075 59 6053 59C6044 59 6038 68 6038 82C6038 87 6038 90 6039 93L6131 472L6121 481L6088 463C6047 478 6030 482 6003 482C5975 482 5955 477 5928 464C5866 433 5833 403 5808 354C5764 265 5733 145 5733 67C5733 23 5748 -11 5767 -11C5804 -11 5884 41 6000 204ZM6048 414C6026 305 6007 253 5973 201C5916 117 5855 59 5823 59C5811 59 5805 72 5805 99C5805 163 5833 280 5868 360C5892 415 5915 433 5963 433C5986 433 6004 429 6048 414ZM6540 365C6543 403 6548 435 6556 476C6545 481 6541 482 6536 482C6505 482 6474 458 6438 407C6399 351 6360 291 6344 256L6376 408C6380 425 6382 438 6382 450C6382 470 6374 482 6359 482C6338 482 6300 461 6226 408L6198 388L6205 368L6237 389C6265 407 6276 412 6285 412C6295 412 6302 403 6302 390C6302 332 6259 126 6219 -2L6229 -9C6244 -4 6260 -1 6283 4L6296 6L6322 126C6340 209 6363 262 6407 319C6441 363 6468 384 6490 384C6505 384 6515 379 6526 365ZM6835 482C6768 482 6615 419 6615 259C6615 182 6660 136 6737 136C6745 136 6756 136 6767 137L6726 99C6710 84 6699 66 6699 52C6699 42 6706 31 6720 19C6651 -4 6523 -48 6523 -159C6523 -230 6593 -276 6702 -276C6831 -276 6944 -204 6944 -121C6944 -85 6923 -49 6880 -14L6820 35C6786 62 6773 81 6773 100C6773 114 6788 128 6800 146C6898 170 6969 253 6969 342C6969 357 6966 376 6965 380C6982 378 6990 378 6999 378C7016 378 7026 379 7049 382L7058 427L7055 433C7027 426 7007 424 6953 424C6953 425 6929 482 6835 482ZM6736 1L6813 -58C6859 -94 6878 -121 6878 -154C6878 -206 6809 -248 6726 -248C6644 -248 6587 -206 6587 -145C6587 -43 6697 -11 6736 1ZM6810 448C6868 448 6897 412 6897 341C6897 238 6849 168 6779 168C6718 168 6686 209 6686 288C6686 383 6737 448 6810 448ZM7387 111L7363 94C7310 56 7262 36 7226 36C7179 36 7150 73 7150 133C7150 158 7153 185 7158 214C7175 218 7284 248 7309 259C7394 296 7433 342 7433 404C7433 451 7399 482 7349 482C7281 496 7171 423 7134 349C7104 299 7074 180 7074 113C7074 35 7118 -11 7190 -11C7247 -11 7303 17 7395 92ZM7172 274C7189 343 7209 386 7238 412C7256 428 7287 440 7311 440C7340 440 7359 420 7359 388C7359 344 7324 297 7272 272C7244 258 7208 247 7163 237ZM7815 365C7818 403 7823 435 7831 476C7820 481 7816 482 7811 482C7780 482 7749 458 7713 407C7674 351 7635 291 7619 256L7651 408C7655 425 7657 438 7657 450C7657 470 7649 482 7634 482C7613 482 7575 461 7501 408L7473 388L7480 368L7512 389C7540 407 7551 412 7560 412C7570 412 7577 403 7577 390C7577 332 7534 126 7494 -2L7504 -9C7519 -4 7535 -1 7558 4L7571 6L7597 126C7615 209 7638 262 7682 319C7716 363 7743 384 7765 384C7780 384 7790 379 7801 365ZM8355 204L8326 77C8322 60 8320 42 8320 26C8320 4 8329 -9 8344 -9C8367 -9 8408 17 8490 85L8483 106C8459 86 8430 59 8408 59C8399 59 8393 68 8393 82C8393 87 8393 90 8394 93L8486 472L8476 481L8443 463C8402 478 8385 482 8358 482C8330 482 8310 477 8283 464C8221 433 8188 403 8163 354C8119 265 8088 145 8088 67C8088 23 8103 -11 8122 -11C8159 -11 8239 41 8355 204ZM8403 414C8381 305 8362 253 8328 201C8271 117 8210 59 8178 59C8166 59 8160 72 8160 99C8160 163 8188 280 8223 360C8247 415 8270 433 8318 433C8341 433 8359 429 8403 414ZM8558 148C8553 97 8547 62 8536 16C8574 -2 8608 -11 8643 -11C8692 -11 8738 7 8789 47C8840 87 8861 124 8861 174C8861 228 8829 257 8755 271L8712 279C8652 290 8633 307 8633 348C8633 401 8678 442 8735 442C8776 442 8814 424 8830 397L8830 342L8853 342C8857 377 8861 404 8872 455C8833 474 8805 482 8772 482C8720 482 8659 452 8611 404C8585 377 8574 352 8574 316C8574 260 8605 228 8671 215L8734 203C8778 195 8794 177 8794 138C8794 73 8748 29 8677 29C8642 29 8611 40 8583 64L8583 148ZM9157 -180C9156 -187 9156 -193 9156 -198C9156 -241 9193 -276 9238 -276C9344 -276 9454 -152 9513 33L9654 473L9643 482C9614 471 9591 465 9569 463L9534 331C9522 284 9487 211 9454 162C9419 111 9370 67 9348 67C9336 67 9327 90 9328 115L9344 322C9346 353 9348 391 9348 419C9348 464 9341 482 9324 482C9311 482 9297 475 9249 442L9167 386L9178 368L9228 398C9233 401 9244 410 9253 410C9267 410 9275 391 9275 358C9275 357 9275 351 9274 343L9257 100L9256 60C9256 18 9274 -11 9299 -11C9336 -11 9420 74 9495 187L9446 16C9395 -161 9345 -234 9275 -234C9240 -234 9213 -207 9213 -172C9213 -167 9214 -159 9215 -150L9205 -146ZM9680 152C9680 46 9725 -11 9808 -11C9863 -11 9923 15 9968 57C10030 116 10074 230 10074 331C10074 425 10024 482 9941 482C9837 482 9680 382 9680 152ZM9904 444C9965 444 9998 399 9998 315C9998 219 9967 113 9923 60C9905 39 9879 27 9848 27C9790 27 9756 72 9756 151C9756 264 9795 387 9844 427C9857 438 9880 444 9904 444ZM10598 473L10591 482L10523 465L10513 414C10498 336 10473 268 10442 221C10383 130 10305 59 10265 59C10257 59 10252 68 10252 85C10252 99 10254 112 10259 137L10316 408C10319 424 10321 438 10321 451C10321 470 10312 482 10298 482C10278 482 10240 461 10166 408L10138 388L10145 368L10177 389C10205 407 10216 412 10225 412C10234 412 10242 403 10242 392C10242 388 10241 378 10240 374L10177 77C10175 68 10173 44 10173 30C10173 7 10188 -11 10208 -11C10271 -11 10392 101 10476 239L10439 97C10432 73 10428 46 10428 31C10428 6 10439 -9 10458 -9C10484 -9 10520 12 10618 85L10608 103L10582 86C10558 70 10532 59 10521 59C10513 59 10508 66 10508 76C10508 112 10583 416 10598 473ZM11640 103L11614 86C11585 67 11563 56 11553 56C11546 56 11540 65 11540 76C11540 86 11542 95 11547 116L11622 413C11626 430 11629 446 11629 454C11629 471 11619 482 11603 482C11574 482 11536 464 11475 421C11412 376 11377 341 11328 272L11358 409C11362 429 11365 444 11365 451C11365 470 11355 482 11339 482C11309 482 11263 460 11208 418C11164 384 11144 363 11079 275L11112 408C11116 424 11118 439 11118 451C11118 470 11109 482 11095 482C11074 482 11036 461 10962 408L10934 388L10941 368C10978 391 11013 414 11020 414C11031 414 11038 404 11038 389C11038 338 10997 145 10956 2L10959 -9L11027 6L11049 108C11073 219 11100 278 11155 338C11197 384 11242 414 11270 414C11277 414 11281 406 11281 393C11281 358 11259 244 11218 69L11202 2L11207 -9L11276 6L11297 113C11313 194 11347 269 11391 318C11446 379 11496 414 11528 414C11536 414 11541 405 11541 389C11541 365 11538 351 11516 264C11476 105 11460 84 11460 31C11460 6 11471 -9 11490 -9C11516 -9 11552 12 11650 85ZM11704 152C11704 46 11749 -11 11832 -11C11887 -11 11947 15 11992 57C12054 116 12098 230 12098 331C12098 425 12048 482 11965 482C11861 482 11704 382 11704 152ZM11928 444C11989 444 12022 399 12022 315C12022 219 11991 113 11947 60C11929 39 11903 27 11872 27C11814 27 11780 72 11780 151C11780 264 11819 387 11868 427C11881 438 11904 444 11928 444ZM12296 420C12317 420 12333 421 12359 424C12248 304 12206 221 12206 121C12206 44 12252 -11 12316 -11C12454 -11 12607 236 12607 384C12607 441 12581 482 12545 482C12532 482 12520 478 12512 470L12462 423L12473 404C12482 410 12491 413 12500 413C12527 413 12543 390 12543 350C12543 202 12446 39 12358 39C12309 39 12278 81 12278 146C12278 251 12317 342 12415 464L12405 482C12385 473 12372 470 12344 470C12316 470 12274 472 12245 475L12233 476C12227 477 12222 477 12221 477C12209 477 12200 475 12189 470C12175 443 12164 407 12151 352L12173 352L12190 394C12197 411 12217 422 12241 422C12274 422 12258 420 12296 420ZM12957 111L12933 94C12880 56 12832 36 12796 36C12749 36 12720 73 12720 133C12720 158 12723 185 12728 214C12745 218 12854 248 12879 259C12964 296 13003 342 13003 404C13003 451 12969 482 12919 482C12851 496 12741 423 12704 349C12674 299 12644 180 12644 113C12644 35 12688 -11 12760 -11C12817 -11 12873 17 12965 92ZM12742 274C12759 343 12779 386 12808 412C12826 428 12857 440 12881 440C12910 440 12929 420 12929 388C12929 344 12894 297 12842 272C12814 258 12778 247 12733 237ZM13611 437L13595 437L13616 549C13632 635 13660 673 13706 673C13736 673 13763 658 13778 634L13788 638C13793 654 13803 685 13811 705L13816 720C13800 727 13769 733 13746 733C13735 733 13719 730 13711 726C13687 715 13605 654 13582 630C13560 608 13548 578 13537 521L13522 442C13481 422 13461 414 13436 405L13431 383L13512 383L13503 327C13473 132 13436 -54 13414 -123C13396 -182 13366 -213 13330 -213C13307 -213 13296 -206 13278 -184L13264 -188C13260 -211 13246 -259 13241 -268C13250 -273 13265 -276 13276 -276C13317 -276 13371 -245 13410 -198C13481 -114 13501 -18 13585 383L13689 383C13693 402 13700 425 13706 439L13702 446C13673 439 13674 437 13611 437ZM14184 365C14187 403 14192 435 14200 476C14189 481 14185 482 14180 482C14149 482 14118 458 14082 407C14043 351 14004 291 13988 256L14020 408C14024 425 14026 438 14026 450C14026 470 14018 482 14003 482C13982 482 13944 461 13870 408L13842 388L13849 368L13881 389C13909 407 13920 412 13929 412C13939 412 13946 403 13946 390C13946 332 13903 126 13863 -2L13873 -9C13888 -4 13904 -1 13927 4L13940 6L13966 126C13984 209 14007 262 14051 319C14085 363 14112 384 14134 384C14149 384 14159 379 14170 365ZM14221 152C14221 46 14266 -11 14349 -11C14404 -11 14464 15 14509 57C14571 116 14615 230 14615 331C14615 425 14565 482 14482 482C14378 482 14221 382 14221 152ZM14445 444C14506 444 14539 399 14539 315C14539 219 14508 113 14464 60C14446 39 14420 27 14389 27C14331 27 14297 72 14297 151C14297 264 14336 387 14385 427C14398 438 14421 444 14445 444ZM15377 103L15351 86C15322 67 15300 56 15290 56C15283 56 15277 65 15277 76C15277 86 15279 95 15284 116L15359 413C15363 430 15366 446 15366 454C15366 471 15356 482 15340 482C15311 482 15273 464 15212 421C15149 376 15114 341 15065 272L15095 409C15099 429 15102 444 15102 451C15102 470 15092 482 15076 482C15046 482 15000 460 14945 418C14901 384 14881 363 14816 275L14849 408C14853 424 14855 439 14855 451C14855 470 14846 482 14832 482C14811 482 14773 461 14699 408L14671 388L14678 368C14715 391 14750 414 14757 414C14768 414 14775 404 14775 389C14775 338 14734 145 14693 2L14696 -9L14764 6L14786 108C14810 219 14837 278 14892 338C14934 384 14979 414 15007 414C15014 414 15018 406 15018 393C15018 358 14996 244 14955 69L14939 2L14944 -9L15013 6L15034 113C15050 194 15084 269 15128 318C15183 379 15233 414 15265 414C15273 414 15278 405 15278 389C15278 365 15275 351 15253 264C15213 105 15197 84 15197 31C15197 6 15208 -9 15227 -9C15253 -9 15289 12 15387 85ZM15924 722L15912 733C15860 707 15824 698 15752 691L15748 670L15796 670C15820 670 15830 663 15830 648C15830 645 15830 640 15827 622C15816 567 15743 182 15728 132C15715 82 15709 52 15709 31C15709 6 15720 -9 15739 -9C15765 -9 15801 12 15899 85L15889 103L15863 86C15834 67 15812 56 15802 56C15795 56 15789 66 15789 76C15789 82 15790 89 15793 104ZM16278 111L16254 94C16201 56 16153 36 16117 36C16070 36 16041 73 16041 133C16041 158 16044 185 16049 214C16066 218 16175 248 16200 259C16285 296 16324 342 16324 404C16324 451 16290 482 16240 482C16172 496 16062 423 16025 349C15995 299 15965 180 15965 113C15965 35 16009 -11 16081 -11C16138 -11 16194 17 16286 92ZM16063 274C16080 343 16100 386 16129 412C16147 428 16178 440 16202 440C16231 440 16250 420 16250 388C16250 344 16215 297 16163 272C16135 258 16099 247 16054 237ZM16683 437L16667 437L16688 549C16704 635 16732 673 16778 673C16808 673 16835 658 16850 634L16860 638C16865 654 16875 685 16883 705L16888 720C16872 727 16841 733 16818 733C16807 733 16791 730 16783 726C16759 715 16677 654 16654 630C16632 608 16620 578 16609 521L16594 442C16553 422 16533 414 16508 405L16503 383L16584 383L16575 327C16545 132 16508 -54 16486 -123C16468 -182 16438 -213 16402 -213C16379 -213 16368 -206 16350 -184L16336 -188C16332 -211 16318 -259 16313 -268C16322 -273 16337 -276 16348 -276C16389 -276 16443 -245 16482 -198C16553 -114 16573 -18 16657 383L16761 383C16765 402 16772 425 16778 439L16774 446C16745 439 16746 437 16683 437ZM17013 390L16957 107C16956 99 16944 61 16944 31C16944 6 16955 -9 16974 -9C17009 -9 17044 11 17122 74L17153 99L17143 117L17098 86C17069 66 17049 56 17038 56C17029 56 17024 64 17024 76C17024 102 17038 183 17067 328L17080 390L17187 390L17198 440C17160 436 17126 434 17088 434C17104 528 17115 577 17133 631L17122 646C17102 634 17075 622 17044 610L17019 440C16975 419 16949 408 16931 403L16929 390ZM17594 390L17538 107C17537 99 17525 61 17525 31C17525 6 17536 -9 17555 -9C17590 -9 17625 11 17703 74L17734 99L17724 117L17679 86C17650 66 17630 56 17619 56C17610 56 17605 64 17605 76C17605 102 17619 183 17648 328L17661 390L17768 390L17779 440C17741 436 17707 434 17669 434C17685 528 17696 577 17714 631L17703 646C17683 634 17656 622 17625 610L17600 440C17556 419 17530 408 17512 403L17510 390ZM17818 152C17818 46 17863 -11 17946 -11C18001 -11 18061 15 18106 57C18168 116 18212 230 18212 331C18212 425 18162 482 18079 482C17975 482 17818 382 17818 152ZM18042 444C18103 444 18136 399 18136 315C18136 219 18105 113 18061 60C18043 39 18017 27 17986 27C17928 27 17894 72 17894 151C17894 264 17933 387 17982 427C17995 438 18018 444 18042 444ZM18861 365C18864 403 18869 435 18877 476C18866 481 18862 482 18857 482C18826 482 18795 458 18759 407C18720 351 18681 291 18665 256L18697 408C18701 425 18703 438 18703 450C18703 470 18695 482 18680 482C18659 482 18621 461 18547 408L18519 388L18526 368L18558 389C18586 407 18597 412 18606 412C18616 412 18623 403 18623 390C18623 332 18580 126 18540 -2L18550 -9C18565 -4 18581 -1 18604 4L18617 6L18643 126C18661 209 18684 262 18728 319C18762 363 18789 384 18811 384C18826 384 18836 379 18847 365ZM18915 388L18922 368L18954 389C18991 412 18994 414 19001 414C19011 414 19019 404 19019 391C19019 384 19015 361 19011 347L18945 107C18937 76 18932 49 18932 30C18932 6 18943 -9 18962 -9C18988 -9 19024 12 19122 85L19112 103L19086 86C19057 67 19034 56 19025 56C19018 56 19012 66 19012 76C19012 86 19014 95 19019 116L19096 420C19100 437 19102 448 19102 456C19102 473 19093 482 19077 482C19055 482 19018 461 18943 408ZM19109 712C19080 712 19051 679 19051 645C19051 620 19066 604 19090 604C19121 604 19145 633 19145 671C19145 695 19130 712 19109 712ZM19433 482C19366 482 19213 419 19213 259C19213 182 19258 136 19335 136C19343 136 19354 136 19365 137L19324 99C19308 84 19297 66 19297 52C19297 42 19304 31 19318 19C19249 -4 19121 -48 19121 -159C19121 -230 19191 -276 19300 -276C19429 -276 19542 -204 19542 -121C19542 -85 19521 -49 19478 -14L19418 35C19384 62 19371 81 19371 100C19371 114 19386 128 19398 146C19496 170 19567 253 19567 342C19567 357 19564 376 19563 380C19580 378 19588 378 19597 378C19614 378 19624 379 19647 382L19656 427L19653 433C19625 426 19605 424 19551 424C19551 425 19527 482 19433 482ZM19334 1L19411 -58C19457 -94 19476 -121 19476 -154C19476 -206 19407 -248 19324 -248C19242 -248 19185 -206 19185 -145C19185 -43 19295 -11 19334 1ZM19408 448C19466 448 19495 412 19495 341C19495 238 19447 168 19377 168C19316 168 19284 209 19284 288C19284 383 19335 448 19408 448ZM19893 722L19881 733C19836 711 19795 697 19721 691L19717 670L19765 670C19783 670 19799 667 19799 647C19799 641 19799 632 19797 622L19755 388C19735 272 19693 80 19667 2L19674 -9L19743 7C19751 64 19765 164 19805 236C19850 317 19953 414 19995 414C20006 414 20017 407 20017 393C20017 375 20012 342 20002 303L19951 107C19945 85 19938 55 19938 31C19938 6 19948 -9 19969 -9C20001 -9 20069 41 20128 85L20118 103L20092 86C20069 71 20043 56 20031 56C20024 56 20018 65 20018 76C20018 88 20021 101 20025 116L20089 372C20095 398 20100 423 20100 447C20100 464 20094 482 20068 482C20033 482 19956 437 19888 374C19855 343 19829 308 19801 273L19797 275ZM20281 390L20225 107C20224 99 20212 61 20212 31C20212 6 20223 -9 20242 -9C20277 -9 20312 11 20390 74L20421 99L20411 117L20366 86C20337 66 20317 56 20306 56C20297 56 20292 64 20292 76C20292 102 20306 183 20335 328L20348 390L20455 390L20466 440C20428 436 20394 434 20356 434C20372 528 20383 577 20401 631L20390 646C20370 634 20343 622 20312 610L20287 440C20243 419 20217 408 20199 403L20197 390Z" fill="rgb(0,0,0)" fill-opacity="1" stroke="rgb(0,0,0)" stroke-opacity="1" stroke-width="8" transform="matrix(0.017,0,0,-0.017,0,0)"></path></g></g></g></g></svg> </svg></center>

The inner svg tag does not have dimensions specified and this throws the following error:
image

Proposal

Would it be possible to implement a way to to detect and catch errors at runtime so that they can be properly handled?

Thanks

@ganeshh123 ganeshh123 added the enhancement New feature or request label Nov 5, 2023
@daohoangson
Copy link
Owner

For widgets that support error reporting, you can handle it in the onErrorBuilder callback. For other things like SVG, you probably need something like this https://github.com/rrousselGit/boundary or implement your own handlers.

@ganeshh123
Copy link
Author

Hi, I already tried the library you mentioned, it's super outdated and I couldn't get it to work. Could you please show me how I can handle the SVG error myself?

I tried flutter onError, but that doesn't seem to catch it.

@daohoangson
Copy link
Owner

I fixed NNBD issues for the lib but it didn't work...
import 'package:flutter/widgets.dart';

typedef BoundaryWidgetBuilder = Widget Function(
  BuildContext context,
  dynamic error,
);

/// No `Boundary<valueType>` were found as an ancestor of a [Defer] was used.
class BoundaryNotFoundError extends Error {
  /// The type of the widget that tried (and failed) to access `Boundary<valueType>`.
  final Type valueType;

  /// Allows specifying [valueType]
  BoundaryNotFoundError(this.valueType);

  @override
  String toString() {
    return '''
Error: No Boundary<$valueType> found.
''';
  }
}

class _InheritedBoundary extends InheritedWidget {
  const _InheritedBoundary({
    this.element,
    required super.child,
  });

  static _BoundaryElement? of(BuildContext context) {
    final widget = context
        .getElementForInheritedWidgetOfExactType<_InheritedBoundary>()
        ?.widget;

    if (widget is _InheritedBoundary) {
      return widget.element;
    }
    return null;
  }

  final _BoundaryElement? element;

  @override
  bool updateShouldNotify(_InheritedBoundary oldWidget) {
    return oldWidget.element != element;
  }
}

/// Defines a fallback behavior for [Defer] widget used inside `child`.
class Boundary extends StatelessWidget {
  /// [fallbackBuilder] and [child] must not be `null`.
  const Boundary({
    super.key,
    required this.fallbackBuilder,
    required this.child,
  });

  /// The subtree from which [Boundary] will capture errors.
  ///
  /// If [child] or any of its descendants throws when building the widget,
  /// then [fallbackBuilder] will be called with the exception.
  final Widget child;

  /// A callback used to create a fallback UI if [child] fails to build.
  ///
  /// It is fine for [fallbackBuilder] to throws too, in which case the error
  /// will be propagated to other boundaries.
  final BoundaryWidgetBuilder fallbackBuilder;

  @override
  _BoundaryElement createElement() => _BoundaryElement(this);

  @override
  Widget build(BuildContext context) {
    return _Internal(
      showChild: true,
      element: context as _BoundaryElement,
      exception: context.exception,
      fallbackBuilder: fallbackBuilder,
      child: child,
    );
  }
}

/// A widget that asks the nearest [Boundary] in its ancestors to call
/// [Boundary.fallbackBuilder].
class Defer extends StatelessWidget {
  /// Allows specifying [details].
  const Defer(this.details, {super.key});

  /// The object that will be passed as parameter to [Boundary.fallbackBuilder].
  final Object details;

  @override
  _FallbackElement createElement() => _FallbackElement(this);

  @override
  Widget build(BuildContext context) => const SizedBox();
}

class _FallbackElement extends StatelessElement {
  _FallbackElement(Defer super.widget);

  @override
  Defer get widget => super.widget as Defer;

  _BoundaryElement? boundary;
  _BoundaryElement? didCatch;

  @override
  Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) {
    final res = super.updateChild(child, newWidget, newSlot);

    final b = boundary = _InheritedBoundary.of(this);
    if (b == null) {
      FlutterError.reportError(
        FlutterErrorDetails(
          library: 'boundary',
          exception: BoundaryNotFoundError(widget.details.runtimeType),
        ),
      );
    } else {
      b.markSubtreeFailed(widget.details);
    }
    return res;
  }

  @override
  void deactivate() {
    final b = boundary;
    if (b != null && b.activated) {
      b.markSubtreeFailed(null);
    }
    super.deactivate();
  }
}

class _Internal extends StatelessWidget {
  const _Internal({
    required this.child,
    required this.element,
    this.exception,
    required this.fallbackBuilder,
    required this.showChild,
  });

  final _BoundaryElement element;
  final Widget child;
  final BoundaryWidgetBuilder fallbackBuilder;
  final dynamic exception;
  final bool showChild;

  @override
  Widget build(BuildContext context) {
    if (exception != null) {
      if (!showChild) {
        element.errorWidget = _InheritedBoundary(
          element: _InheritedBoundary.of(context),
          child: Builder(
            builder: (context) => fallbackBuilder(context, exception),
          ),
        );
      }
    } else {
      element.errorWidget = null;
    }

    final valid = Offstage(
      offstage: !showChild && exception != null,
      child: child,
    );

    final errorWidget = element.errorWidget;

    return _InheritedBoundary(
      element: element,
      child: Stack(
        fit: StackFit.passthrough,
        alignment: Alignment.center,
        children: [valid, if (errorWidget != null) errorWidget],
      ),
    );
  }
}

class _BoundaryElement extends StatelessElement {
  _BoundaryElement(Boundary super.widget);

  @override
  Boundary get widget => super.widget as Boundary;

  Object? failure;
  bool isBuilding = false;
  bool activated = false;
  dynamic exception;
  Widget? errorWidget;

  Element? _child;
  dynamic _slot;

  @override
  Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) {
    _child ??= child;
    _slot = newSlot;
    return _child = super.updateChild(child, newWidget, newSlot);
  }

  @override
  void performRebuild() {
    isBuilding = true;
    final hadError = failure != null;
    failure = null;
    super.performRebuild();
    isBuilding = false;
    final hasError = failure != null;
    if (hasError != hadError) {
      exception = failure;
      rebuildWithError(exception);
    }
  }

  @override
  void mount(Element? parent, Object? newSlot) {
    super.mount(parent, newSlot);
    activated = true;
  }

  @override
  void activate() {
    super.activate();
    activated = true;
  }

  @override
  void deactivate() {
    activated = false;
    super.deactivate();
  }

  void markSubtreeFailed(Object? failure) {
    this.failure = failure;
    exception = failure;
    if (!isBuilding) {
      rebuildWithError(exception);
    }
  }

  void rebuildWithError(dynamic exception) {
    updateChild(
      _child,
      _Internal(
        element: this,
        showChild: false,
        fallbackBuilder: widget.fallbackBuilder,
        exception: exception,
        child: widget.child,
      ),
      _slot,
    );
  }
}

Turned out the vector_graphics package (the one being used in flutter_svg) does async operation outside of the rendering pipeline so its error cannot be caught that way. I switched to use VectorGraphic directly in order to set an errorBuilder but it still cannot catch the error. Finally I found this bug report dnfield/flutter_svg#996.

I guess we will have to wait for error builder to be included in flutter_svg. Then I will update fwfh_svg to make use of that callback and handle bad SVG gracefully.

@ganeshh123
Copy link
Author

Thank you for taking the time to investigate the problem, I appreciate it.

Let's hope the fix will be implemented soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants