Пример #1
0
/*
 * call-seq:
 *   error -> HASH
 *
 * Retrieve details about the last error encountered and return those
 * details in a HASH with the following entries:
 * - :code    error code from +aug_error+
 * - :message error message from +aug_error_message+
 * - :minor   minor error message from +aug_minor_error_message+
 * - :details error details from +aug_error_details+
 */
VALUE augeas_error(VALUE s) {
    augeas *aug = aug_handle(s);
    int code;
    const char *msg;
    VALUE result;

    result = rb_hash_new();

    code = aug_error(aug);
    hash_set(result, "code", INT2NUM(code));

    msg = aug_error_message(aug);
    if (msg != NULL)
        hash_set(result, "message", rb_str_new2(msg));

    msg = aug_error_minor_message(aug);
    if (msg != NULL)
        hash_set(result, "minor", rb_str_new2(msg));

    msg = aug_error_details(aug);
    if (msg != NULL)
        hash_set(result, "details", rb_str_new2(msg));

    return result;
}
Пример #2
0
static void print_aug_error(void) {
    if (aug_error(aug) == AUG_ENOMEM) {
        fprintf(stderr, "Out of memory.\n");
        return;
    }
    if (aug_error(aug) != AUG_NOERROR) {
        fprintf(stderr, "error: %s\n", aug_error_message(aug));
        if (aug_error_minor_message(aug) != NULL)
            fprintf(stderr, "error: %s\n",
                    aug_error_minor_message(aug));
        if (aug_error_details(aug) != NULL) {
            fputs(aug_error_details(aug), stderr);
            fprintf(stderr, "\n");
        }
    }
}
Пример #3
0
/* Internal helper to help extract errors */
static std::string augeasGetError() {
    std::vector<std::string> result;
    int err = aug_error(augeas);
    if(!err)
        return "";

    std::stringstream msg;
    const char *p;
    if((p=aug_error_message(augeas)))
        msg << p;

    if((p=aug_error_minor_message(augeas)))
        msg << " (" << p << ")";

    if((p=aug_error_details(augeas)))
        msg << " (" << p << ")";

    switch(err) {
        case AUG_EPATHX:
            return std::string("Bad section/app used: " + msg.str());
        default:
            return msg.str();
    }
}
Пример #4
0
static int Paug_error_minor_message(lua_State *L)
{
    augeas *a = Paug_checkarg(L, 1);
    lua_pushstring(L, aug_error_minor_message(a));
    return 1;
}