shorebird icon indicating copy to clipboard operation
shorebird copied to clipboard

fix: The patch makes tryCatch invalid

Open LinXunFeng opened this issue 2 months ago • 11 comments

App ID: N/A

Description

In version 1.0, the tryCatch in the following code will become invalid after the patch is applied.

List<String> list = ['a', 'b'];
bool _isExist(String type) {
  try {
    final model = list.firstWhere(
      (element) => element.type == type,
    );
    return true;
  } catch (e) {
    return false;
  }
}

_isExist('c');
String value = '';
...
try {
  return json.decode(value);
} catch (e) {
  return null;
}

I'm glad this issue has been fixed in version 1.0.1, but I found that the following code still makes tryCatch invalid, even in the latest version 1.0.4.

class HexColor extends Color {
  static int _getColorFromHex(String hexColor) {
    try {
      hexColor = hexColor.toUpperCase().replaceAll("#", "");
      if (hexColor.length == 6) {
        hexColor = "FF$hexColor";
      }
      return int.parse(hexColor, radix: 16);
    } catch (e) {
      return 0x00000000;
    }
  }

  HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}

HexColor('');

The strange thing is that I new a demo and used the above code. I wanted to reproduce this problem but couldn't. It can only be reproduced in our commercial project.

This issue prevents our page from displaying properly, and it only appears on iOS.

Expected Behavior

The page can be displayed properly.

Additional Context

shorebird --version
Shorebird 1.0.4 • [email protected]:shorebirdtech/shorebird.git
Flutter 3.19.6 • revision aee5222c0d52012f089564a8395826d56e7c2fe8
Engine • revision e4434d7a212b29a8ee8ffaf8e2c453c753904933

LinXunFeng avatar Apr 29 '24 08:04 LinXunFeng