-
Notifications
You must be signed in to change notification settings - Fork 11
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
Bug: Custom exception not thrown #48
Labels
bug
Something isn't working
Comments
Not important, but if you are curious, this is the code that caught the bug: Bdd(feature)
.scenario('Selling stocks you don’t have.')
.given('The user has 120 dollars in cash-balance.')
.and('IBM price is 30 dollars.')
.and('The user has no IBM stocks.')
.when('The user sells 1 IBM.')
.then('We get an error.')
.and('The user continues to have 0 IBM.')
.and('The cash-balance continues to be 120 dollars.')
.run((ctx) async {
// Given:
var ibm = AvailableStock('IBM', name: 'IBM corp', currentPrice: 30.00);
var state = AppState.from(cashBalance: 120.00, availableStocks: [ibm]);
expect(state.portfolio.stocks, isEmpty); // No IBM.
var storeTester = StoreTester(initialState: state);
await celest.functions.admin.setDatabase(state.portfolio, state.availableStocks.list);
// When:
var info = await storeTester.dispatchAndWait(
SellStock_Action(ibm, howMany: 1),
);
// Then:
expect(info.error, isAError<MyException>('Cannot sell stock you do not own'));
expect(info.state.portfolio.howManyStocks(ibm.ticker), 0);
expect(info.state.portfolio.cashBalance, CashBalance(120.00));
}); And the console output is:
|
Great guess! You're absolutely right that's how I handle it 😆 I had done AST probing before landing on Thanks for bringing this up! |
Tracking the DRY'ing of the exception handling in a separate issue: #49 |
Merged
This has been fixed in 0.2.0! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey guys, the tests of my Celest demonstration app caught an error. I just verified it's actually not in the app code, but in the Celest code.
If I write this function definition it works and throws
MyException
:However, if I change it like the following, instead of throwing
MyException
, it throws aBadRequestException("MyException")
:In the first case, the generated code is this:
But the second one is missing the
MyException
serialization:I'd say the problem is that you are most likely inspecting the AST of the
sellStock
definition, and not findingMyException
in there in the second case, so you are not serializing it, right? But you should check all function calls too. This can be very complex; it will not be possible to check all possible code paths.I think you are overcomplicating this. There is no need to search for exceptions in the AST, but simply create a helper function like the
_processErrors
below, which checks all possible cloud exceptions exported fromexceptions.dart
:And then use that, for all functions:
Not to mention that the original code is very repetitive, and removing it will also save memory. When generating code it's easy to remember to apply the DRY principle to the code we actually wrote, but forget to apply it to the generated code itself.
The text was updated successfully, but these errors were encountered: