You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users of my Async Redux package can display an error dialog to the user by simply throwing a UserException which is provided by the package itself. For example:
class SellStockAction extends ReduxAction {
final Stock stock;
final int howMany;
AppState? reduce() {
if (state.stocks.contain(stock)) return state.copy(stocks: stocks.sell(howMany));
else throw UserException('You don't have any stocks of ${stock.ticker} to sell.');
}
}
But now I want to modify this code to create a Celest function called sell that throws a UserException internally:
class SellStockAction extends ReduxAction {
final Stock stock;
final int howMany;
Future<AppState?> reduce() async {
var stocks = await celest.functions.stocks.sell(stock, howMany); // This function may throw UserException.
return state.copy(stocks: stocks);
}
}
Since UserException is defined in the Async Redux package, I can't move it to the exceptions directory.
Is it possible to force Celest to accept/serialize an exception that I'll import from another package?
The text was updated successfully, but these errors were encountered:
Hi @marcglasberg, the condition for custom models and exceptions is that they be exported from models.dart/exceptions.dart, but do not have to be defined within.
So, you could have the following in exceptions.dart (although you'd run into #35 because of Object?).
export'package:async_redux/async_redux.dart'show UserException;
// ... Other custom exception types.
I understand this requirement is a bit confusing and we're looking at better alternatives. In the meantime, I will go through our docs and see how we can better explain this.
marcglasberg
changed the title
Force Celest to accept/serialize an exception imported from another package
Explain in the docs that Celest can serialize an exception imported from another package
Feb 10, 2024
That's great! I renamed this issue to Explain in the docs that Celest can serialize an exception imported from another package. Just make it clear in the documentation.
Users of my Async Redux package can display an error dialog to the user by simply throwing a
UserException
which is provided by the package itself. For example:But now I want to modify this code to create a Celest function called
sell
that throws aUserException
internally:Since
UserException
is defined in the Async Redux package, I can't move it to theexceptions
directory.Is it possible to force Celest to accept/serialize an exception that I'll import from another package?
The text was updated successfully, but these errors were encountered: