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

Set immediate error callbacks #1348

Closed

Conversation

dallonf
Copy link

@dallonf dallonf commented Mar 1, 2017

This is an attempt to fix #1141 . Unfortunately I had a lot of trouble testing this - it's just hard to coerce Mocha to allow uncaught exceptions.

Copy link
Contributor

@calebmer calebmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use setTimeout instead of setImmediate? I’m going to look at the tests now and see why they are complaining.

console.error(`Error in observer.error \n${e.stack}`);
}
// defer to avoid potential errors propagating back to Apollo
(setImmediate || setTimeout)(() => observer.error(apolloError));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use setTimeout(() => { ... }, 0) here? Is there any advantage to using setImmediate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setImmediate was called out explicitly in this comment, not sure if there's a real advantage, or if it's enough to offset the loss in readability. I can drop it!

@@ -438,11 +435,10 @@ export class QueryManager {

if (isDifferentResult) {
lastResult = resultFromStore;
try {
// defer to avoid potential errors propagating back to Apollo
(setImmediate || setTimeout)(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@calebmer
Copy link
Contributor

calebmer commented Mar 2, 2017

It looks like TypeScript is failing in CI and not the actual tests. Could you try changing the Observer type to:

export interface Observer<T> {
  readonly next?: (value: T) => void;
  readonly error?: (error: Error) => void;
  readonly complete?: () => void;
}

I think I recall readonly fixing this error in the past for me.

@abhiaiyer91
Copy link
Contributor

@calebmer tried applying your TS type fix but you still receive TS errors error TS2532: Object is possibly 'undefined'.?

Dallon Feldner added 3 commits March 3, 2017 08:21
@dallonf
Copy link
Author

dallonf commented Mar 3, 2017

Went ahead and fixed the type errors. Now we're getting into the weird test stuff. I might be able to figure out how to fix some of them.

@calebmer
Copy link
Contributor

calebmer commented Mar 3, 2017

@abhiaiyer91 the current commit should fix the errors 😊

@dallonf
Copy link
Author

dallonf commented Mar 3, 2017

For the QueryManager result transformation transforms watchQuery() results test, it's failing because the response has actually been transformed three times: once in QueryManager.ts (line 443, when calling observer.next()), once in ObservableQuery.ts(line 198, in refetch after calling queryManager.fetchQuery()), and then again in the same place as the first time.

It was calling it three times before the changes in this PR, but the third call was made after the assertion, so the test passed. Now the timing has changed subtly. I have no idea what the desired behavior is here... it's possible there was already a bug here that the tests didn't catch until now.

@dallonf
Copy link
Author

dallonf commented Mar 3, 2017

Similarly, the client forceFetch can temporarily be disabled with ssrForceFetchDelay test fails because it's very dependent on the subtle timing of the observer.

I wonder if it would be a less impactful solution to do something like this...

try {
  observer.next(/*...*/)
} catch( err) {
  // throw error outside the current flow
 setTimeout(() => { throw err; }, 0); 
}

It's a lot harder to read and understand what's going on, but it would probably break fewer tests. (And I have to wonder if other libraries and apps that depend on apollo-client depend on this sort of timing in subtle ways)

@calebmer
Copy link
Contributor

calebmer commented Mar 3, 2017

I doubt this change actually breaks real apps. It’s unfortunate that it breaks a lot of tests 😣

@dallonf
Copy link
Author

dallonf commented Mar 6, 2017

Yeah, had a much easier time with that approach: #1367. Let me know if I should close this one if you'd rather go with this approach and somehow fix all the tests.

@calebmer
Copy link
Contributor

calebmer commented Mar 6, 2017

Yeah, #1367 looks really nice. I don’t think there is any real substantial difference between the two approaches. Since the tests are green let’s pursue that one 👍

@calebmer calebmer closed this Mar 6, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discussion/feature request: custom error handling
3 participants