Skip to content

Conversation

TiborGY
Copy link
Contributor

@TiborGY TiborGY commented Sep 3, 2022

Description

Errors in PSIO should probably be handled by calling psio_error(...), instead of printing the error messages from the function where the error happens.

This PR renovates this function to something more C++-style, and adds a new string argument that defaults to the empty string. This allows the callers of the function to prepend their own error messages to the text that eventually ends up in the error box, such as OS supplied error messages when a read/write/lseek system call fails.

This should make it easier to clean up wt_toclen etc. (see #2700)

Todos

  • psio_error(...) can now take a string argument that will be printed first
  • Unnecessary includes are removed
  • Fixed size char array and C-style string manipulation is gone

Status

  • Ready for review
  • Ready for merge

void psio_error(size_t unit, size_t errval) {
int i;
fprintf(stderr, "PSIO_ERROR: unit = %zu, errval = %zu\n", unit, errval);
void psio_error(size_t unit, size_t errval, std::string prev_msg /* = ""*/) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a matter of style, how do other developers feel about the /* = ""*/ to note the optional argument in the *.cc file in addition to the *.h file? I oppose it as redundant.

Otherwise, LGTM. Thanks for the renovation. Will approve once the above issue is sorted.

Copy link
Member

Choose a reason for hiding this comment

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

I had thought some doc scheme picked up on the c-style parameter comments, but I'm not finding evidence. here's a SO on the topic https://stackoverflow.com/a/4989591 . I'm content with having the /* = ""*/ since (1) it's not a blah.h and blah.cc pair and (2) unlikely to fall out-of-date. But I'm not adamant.

Copy link
Contributor

Choose a reason for hiding this comment

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

FTR, I'm not adamant either, just want dev discussion.

@loriab loriab added this to the Psi4 1.7 milestone Sep 6, 2022
@loriab loriab added the cleanup For issues where the goal is to make Psi4 a little cleaner. label Sep 6, 2022
Copy link
Member

@loriab loriab left a comment

Choose a reason for hiding this comment

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

lgtm! thanks for venturing to improve psio

@jturney jturney merged commit dc5001f into psi4:master Sep 15, 2022
@TiborGY TiborGY deleted the psio_error_revamp branch September 24, 2022 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup For issues where the goal is to make Psi4 a little cleaner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants