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
Conversation
Rework error handling in example code so we always check return values, but without cluttering the documentation.
[-Werror=declaration-after-statement]
This reverts commit 90339af.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
@keithbostic I pushed a fix for the |
examples/c/ex_call_center.c
Outdated
} | ||
/* Note: further error checking omitted for clarity. */ | ||
home = example_setup(argc, argv); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@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 macroscan_end_check
which checks thatret == 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
andscan_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:
session->transaction_sync
call inex_sync.c
that returns failure, can you please take a look and fix it?join_cursor->next
call inex_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.