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

WT-1939 Improve error handling in example code #3467

Merged
merged 7 commits into from Jun 26, 2017

Conversation

keithbostic
Copy link
Contributor

@agorrod, @sueloverso: I took a run at cleaning up the example code error handling.

I hope this resolves WT-3364 and WT-1939.

I ended up using Alex's technique from the test/utility code, adding two macros: first, a macro error_check that checks for a non-zero return from a function call, and second, a macro scan_end_check which checks that ret == WT_NOTFOUND after a cursor scan completes.

I decided against adding explicit error checking with messages because I doubt our ability to ever exercise those error message paths and the error handling messages clutters the documentation more than I wanted.

I chose the names error_check and scan_end_check to hopefully make it clear in the documentation what's going on, happy to switch to something else if anybody has a better idea.

I found and fixed a few places in the example code where we weren't checking error returns and the example code fails, but there were two I didn't fix:

  • @sueloverso, there's a session->transaction_sync call in ex_sync.c that returns failure, can you please take a look and fix it?
  • @ddanderson, there's a join_cursor->next call in ex_stat.c that returns failure, can you please take a look and fix it?

Both of those calls are currently commented out so the tests pass, just search for KEITH in the file to find the call.

Rework error handling in example code so we always check return values,
but without cluttering the documentation.
Copy link
Member

@ddanderson ddanderson left a comment

Choose a reason for hiding this comment

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

@keithbostic These changes look great to me. I had one comment, and I fixed the join example in ex_stat.c

char cmd_buf[256];

(void)argc; /* Unused variable */
(void)testutil_set_progname(argv);

(void)snprintf(cmd_buf, sizeof(cmd_buf),
"rm -rf %s && mkdir %s", home, home);
Copy link
Member

Choose a reason for hiding this comment

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

Could this be replaced by home = example_setup(argc, argv); like other examples?

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 think so, but I'll leave that up to @sueloverso: ex_backup.c has its own set of 3 databases, and the naming is clearly intended to align between the 3, so I was hesitant to change it.

Copy link
Member

Choose a reason for hiding this comment

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

That test does a lot of directory manipulation. It actually uses a larger number as it creates a differently numbered incremental database directory for each successive pass. I suggest leaving it alone and it is likely a one-off and its usage is not worth making into a higher level function.

@agorrod
Copy link
Member

agorrod commented Jun 19, 2017

Thanks @keithbostic I really like the direction you went with this change.

FYI: Sue is on vacation this week - so this is likely to sit until she gets back.

@sueloverso
Copy link
Member

@keithbostic I pushed a fix for the ex_sync failure.

}
/* Note: further error checking omitted for clarity. */
home = example_setup(argc, argv);

Copy link
Member

Choose a reason for hiding this comment

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

very minor nit: since home is used in the next line, I'd remove the blank line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@keithbostic keithbostic merged commit 7447cce into develop Jun 26, 2017
@keithbostic keithbostic deleted the wt-1939-example-error-handling branch June 26, 2017 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants