Skip to content

Commit

Permalink
Format error messages to remove stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnet3 committed Sep 10, 2024
1 parent bc6ad9d commit d3fde8a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/global_functions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:danawallet/widgets/input_alert_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

final globalNavigatorKey = GlobalKey<NavigatorState>();

Expand Down Expand Up @@ -50,3 +51,14 @@ Future<String?> showInputAlertDialog(TextEditingController controller,
return Future.value(null);
}
}

String exceptionToString(Object e) {
String message;
if (e is AnyhowException) {
// remove stack trace from anyhow exception
message = e.message.split('\n').first;
} else {
message = e.toString();
}
return message;
}
2 changes: 1 addition & 1 deletion lib/screens/home/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SettingsScreen extends StatelessWidget {
final wallet = await walletState.getWalletFromSecureStorage();
return showMnemonic(encodedWallet: wallet);
} catch (e) {
displayNotification(e.toString());
displayNotification(exceptionToString(e));
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/wallet/spend/spend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class SpendScreenState extends State<SpendScreen> {
} catch (e) {
setState(() {
_isSending = false;
_error = e.toString();
_error = exceptionToString(e);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/wallet/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class WalletScreenState extends State<WalletScreen> {
await chainState.updateChainTip();
await walletState.scan();
} catch (e) {
displayNotification(e.toString());
displayNotification(exceptionToString(e));
}
},
child: const Text('Scan'));
Expand Down
2 changes: 1 addition & 1 deletion lib/services/synchronization_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SynchronizationService {
final chainState = Provider.of<ChainState>(context, listen: false);
await chainState.updateChainTip();
} catch (e) {
displayNotification(e.toString());
displayNotification(exceptionToString(e));
}
}

Expand Down

0 comments on commit d3fde8a

Please sign in to comment.