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

Explain in the docs that Celest can serialize an exception imported from another package #39

Open
marcglasberg opened this issue Feb 8, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@marcglasberg
Copy link

marcglasberg commented Feb 8, 2024

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?

@dnys1
Copy link
Member

dnys1 commented Feb 9, 2024

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.

@dnys1 dnys1 added question Further information is requested and removed feature request labels Feb 9, 2024
@marcglasberg 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
@marcglasberg
Copy link
Author

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.

@abdallahshaban557 abdallahshaban557 added documentation Improvements or additions to documentation and removed question Further information is requested labels Feb 10, 2024
@abdallahshaban557
Copy link
Contributor

abdallahshaban557 commented Feb 10, 2024

Aaaand that's my cue. I'll get it updated ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: Ready
Development

No branches or pull requests

3 participants