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

Refactor NetDaemonHost.HandleNewEvent #339

Merged
merged 2 commits into from Apr 1, 2021

Conversation

FrankBakkerNl
Copy link
Contributor

@FrankBakkerNl FrankBakkerNl commented Mar 28, 2021

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]
  • The code compiles without warnings (code quality chek)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

}
}, token));
}
observer.OnError(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if this is actually the corrcet way tp handle errors in Observables. I think OnError should be calles when the producers causes an error, not the observer. The same patteren is repeated here a coupe of times slightly different.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok well I need to revisit this again. Not sure. Was a quite a time ago I implemented

foreach (var netDaemonRxApp in NetDaemonRxApps)
{
// Call the observable with no blocking
foreach (var observer in ((StateChangeObservable)netDaemonRxApp.StateChangesObservable).Observers)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to Create a property StateChangesObservables like I did for the other one, but here the netDaemonRxApp is used for logging. The other events do not log using the app so maybe that is not actually needed

}
}, token));
}
observer.OnError(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is even more complicated, in the catch call OnError in another try catch. If this is really needed (what I doubt) this behaviour can probably extracted in a wrapper for the observer. Otherwise It would be enough to just catch and maybe log all exceptions from eventhanders

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea if we gonna refactor the error handling we need to test it so we make sure all exceptions are logged and the process continue handle messages. But you are probably right.

@helto4real
Copy link
Collaborator

@FrankBakkerNl thanks for this. Sorry for being late merging. Been busy times at work. I will check it tomorrow, there are some removed code I need to think about if it is ok. Looks good overall !

}
}, token));
}
observer.OnError(e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now I think I know why I did this design. This is so I will pass any exception back to app so apps can also handle exceptions or they would go silent if I remember correctly

}
}, token));
}
observer.OnError(e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea if we gonna refactor the error handling we need to test it so we make sure all exceptions are logged and the process continue handle messages. But you are probably right.

@helto4real helto4real merged commit 3097109 into net-daemon:dev Apr 1, 2021
@FrankBakkerNl FrankBakkerNl deleted the refactor_NetDeamonHost branch April 4, 2021 05:16
Ikcelaks pushed a commit to Ikcelaks/netdaemon that referenced this pull request Dec 23, 2022
* Refactor NetDaemonHost.HandleNewEvent

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants