-
Notifications
You must be signed in to change notification settings - Fork 6
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
Errors through "Include" are not relayed #1
Comments
The test case: #include <stdio.h>
#include <dotconf.h>
#include <string.h>
#include <stdlib.h>
static DOTCONF_CB(option);
static const configoption_t options[] = {
{"error", ARG_RAW, option, NULL, CTX_ALL},
LAST_OPTION
};
FUNC_ERRORHANDLER(error_handler) {
printf("Error handler executed\n");
return 1;
}
void do_test(const char *file) {
printf("\nOpening %s\n", file);
configfile_t *c = dotconf_create(strdup(file), options, NULL, CASE_INSENSITIVE);
c->errorhandler = (dotconf_errorhandler_t) error_handler;
int res = dotconf_command_loop(c);
dotconf_cleanup(c);
if(res == 0)
printf("dotconf_command_loop() failed\n");
}
int main() {
do_test("error.conf");
do_test("ok.conf");
do_test("include_error.conf");
}
static DOTCONF_CB(option) {
// find 0 or 1 in data
int i;
int len = strlen(cmd->data.str);
for(i = 0; i < len; ++i) {
if(cmd->data.str[i] == '0') return NULL;
if(cmd->data.str[i] == '1') return "Error found";
}
return "No error found";
} |
A work-around is to keep error state in the context variable, setting it to "no error" before starting to parse, and setting it to "error" in the error handler. The error handler is called for every error regardless of what file they are in, so this allows you to see an error did occur even though |
sgielen
added a commit
to dazeus/dazeus-core
that referenced
this issue
Feb 19, 2013
…otconf_command_loop(), use state->error to detect whether an error occured in an included file
sgielen
added a commit
to dazeus/dazeus-core
that referenced
this issue
Mar 6, 2013
…otconf_command_loop(), use state->error to detect whether an error occured in an included file
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When a parsing error is introduced in a DOTCONF_CB function by returning a non-NULL charptr, dotconf_command_loop() is supposed to return 0 indicating failure to parse. This works fine for the main configuration file, but not if errors are found in included configuration files. I will attach a test case shortly, where the following configuration file fails as expected:
The following file succeeds as expected:
And the following file succeeds unexpectedly, while it does invoke the error handler:
The text was updated successfully, but these errors were encountered: