Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Conversation

mliszcz
Copy link
Collaborator

@mliszcz mliszcz commented Jan 26, 2019

Per @bourtemb suggestion from #514 let's handle unsubscribe_event failures in ~DeviceProxy to prevent exceptions being thrown out of a destructor.

Copy link
Member

@bourtemb bourtemb left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution @mliszcz!
I suggest to remove a useless empty line (just to have something to write on my review)... Except that, this PR looks very good to me!

{
}
}

Copy link
Member

Choose a reason for hiding this comment

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

The only improvement I could think of is to take the opportunity of this Pull Request to remove this empty line.
@mliszcz, could you do that, please?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mliszcz @bourtemb How about getting also rid of the useless if (ids.empty() == false)? And I would also include a message output in catch(...) as reaching that branch seems fishy to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for reviewing the PR!

@bourtemb I've removed the redundant line.

@t-b I've removed the empty() check. I've also did a few cosmetic changes and renames. I don't know what is the preferred coding style, so please check those as well.

As for the error message in catch(...), I've added a printout. Is there a logger for client API that can print at least the file and line number?
BTW In my opinion a library should not print anything to std out/err, but in case of d-tor failure there is no other way to notify the user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mliszcz Looks better! Regarding the printout I would print to cerr as that is what Except::print_exception does as well, IIRC this is a log stream and not the same as std::cerr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@t-b thanks for checking! I've already looked into print_exception and my assumption was that cerr is std::cerr. cerr would be very unfortunate name for a custom logger stream, especially that tango.h includes iostream and brings std into default scope.

Following grep does not yield any meaningful result: grep -r cerr | grep -v 'cerr <<'
Seems that cerr actually IS std::cerr. Would it be ok for you if I'll leave the namespace in the name as it is now?

Copy link
Member

Choose a reason for hiding this comment

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

@t-b, thanks for the review and the good catch for the empty() if.

cout (not cerr) is redirected to the log stream, except if the library is compiled in Debug mode on Linux (_TANGO_LIB compilation flag is not set in this case). In Debug mode on Linux, cout is the standard std::cout.

There is the following code in cppapi/server/logging.h:

#ifdef _TANGO_LIB //== compiling TANGO lib ====================

//-- Overwrite std::cout  -------------------------------------
#define cout \
    if (API_LOGGER) \
      API_LOGGER->get_stream(log4tango::Level::INFO, false) \
        << log4tango::LogInitiator::_begin_log

#endif //== compiling TANGO lib ===============================

It looks like _TANGO_LIB is always defined when compiling the Tango library on Windows... So it seems cout is always redirected to the log stream on Windows, even when the library is compiled in Debug mode.

cerr is actually always std:cerr with the current source code.

As for the error message in catch(...), I've added a printout. Is there a logger for client API that can print at least the file and line number?

Not yet.

Would it be ok for you if I'll leave the namespace in the name as it is now?

With the current code, I don't see any problem with that since cerr is std::cerr.
The question is: do we want to use a trick at some point to overload cerr with something else in a similar way as it was done for cout?
I would say if it's the case in the future, we can always modify this part of the code if needed...
We could also use cout3 to log a message to the logging system.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bourtemb Thanks for the insight. I'm fine with keeping it as is. We should only very rarely reach catch(...).

@mliszcz mliszcz force-pushed the unsubscribe-event-failure-in-device-proxy-dtor branch from 11df11e to c59e50d Compare January 28, 2019 19:35
{
std::cerr
<< "Unknown exception thrown from unsubscribe_event() event_id="
<< *event_id << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also add the name of the device in the error message as well as the current method name.
So I would suggest to change the error message with something like:

std::cerr << " DeviceProxy::unsubscribe_all_events(): Unknown exception thrown from unsubscribe_event() for device \""
             << name() << "\" and event_id=" << *event_id << " std::endl;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I've updated the code according to your suggestion.

@mliszcz mliszcz force-pushed the unsubscribe-event-failure-in-device-proxy-dtor branch 2 times, most recently from efc70df to 7bd96c1 Compare January 31, 2019 20:49
{
std::cerr <<
"DeviceProxy::unsubscribe_all_events(): "
"Unknown exception thrown from unsubscribe_event() for"
Copy link
Member

Choose a reason for hiding this comment

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

a space is missing at the end between "for" and "device"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Fixed.

@mliszcz mliszcz force-pushed the unsubscribe-event-failure-in-device-proxy-dtor branch from 7bd96c1 to c5c4793 Compare February 3, 2019 18:55
@bourtemb bourtemb merged commit 2886a7f into tango-controls:tango-9-lts Feb 26, 2019
Ingvord pushed a commit that referenced this pull request Mar 29, 2019
* Added CHANGELOG.md
This file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
List changes since cppTango 9.2.5.
Changes with potential compatibility issues are documented as suggested in #509 and are in bold.

* Add links to issues and PRs in CHANGELOG.md

* Update CHANGELOG.md
with references to #508,#516,#518,#520,#521,#522,#523,#529,#531,#533,#537

* Update CHANGELOG.md with #517

* Update CHANGELOG.md. Add link for issue 395

* Moved 2 items from Fixed to Changed section
Added a warning about the event subscription change sleep reduction

* First version of the release notes for cppTango 9.3.3
Rename RELEASE_NOTES in RELEASE_NOTES.md.
The previous RELEASE_NOTES content has been moved to CHANGELOG.md file.

* Added reference to cppTango#539
Preparation for cppTango 9.3.3 release

* Update CHANGELOG and RELEASE_NOTES with #541 and #542

* Reword one item in CHANGELOG.md and RELEASE_NOTES.md

* Update CHANGELOG.md with #544, #546 and #549

* Add reference to #532
Add 9.3.3 release date

* Add 9.3.3 release date
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.

3 participants