Remove error messages traceback (there's gdb)

Move "internal error" to print_int_error function
This commit is contained in:
Nikita Ivanov 2022-07-24 23:59:32 +05:00
parent 2f94ff15af
commit 8b79ff432f
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 21 additions and 28 deletions

View File

@ -3,8 +3,6 @@
#include "error.h" #include "error.h"
#include "utils.h" #include "utils.h"
int err_internal_error = 0;
void print_error(const char *error_msg) void print_error(const char *error_msg)
{ {
/* We print errors to stdout because lf file manager /* We print errors to stdout because lf file manager
@ -15,7 +13,21 @@ void print_error(const char *error_msg)
void print_errorf(const char *format, ...) void print_errorf(const char *format, ...)
{ {
char s[1024]; char s[512];
FORMATTED_STRING(s, format); FORMATTED_STRING(s, format);
print_error(s); print_error(s);
} }
void print_int_error(const char *file, unsigned long line, const char *msg)
{
print_errorf("%s:%lu: internal error: %s", file, line, msg);
}
void print_int_errorf(const char *file, unsigned long line, const char *format, ...)
{
char s[512];
FORMATTED_STRING(s, format);
print_int_error(file, line, s);
}

View File

@ -6,37 +6,19 @@
#include "utils.h" #include "utils.h"
#define INTERRMSG "internal error: "
/*
* Add error source to error message
*/
#define ERRSRC(msg) (__FILE__ ":" STRINGIZE(__LINE__) ": " msg)
/* /*
* Print internal error * Print internal error
*/ */
#define PRINTINTERR(format, ...) \ #define PRINTINTERR(format, ...) \
print_error##__VA_OPT__(f)(ERRSRC(format) __VA_OPT__(, ) __VA_ARGS__) print_int_error##__VA_OPT__(f)(__FILE__, __LINE__, format __VA_OPT__(, ) __VA_ARGS__)
#define FUNCFAILED(f, ...) \ #define FUNCFAILED(f, ...) \
PRINTINTERR(INTERRMSG f "() failed" __VA_OPT__(": %s", __VA_ARGS__)) PRINTINTERR(f "() failed" __VA_OPT__(": %s", __VA_ARGS__))
#ifndef NO_TRACEBACK
#define ERRCHK_PRINT_(...) \
do { \
int __a = 0; \
__VA_OPT__(PRINTINTERR(__VA_ARGS__); __a = err_internal_error = 1;) \
if (!__a && err_internal_error) \
PRINTINTERR(); \
} while (0)
#endif
#ifdef NO_TRACEBACK
#define ERRCHK_PRINT_(...) \ #define ERRCHK_PRINT_(...) \
do { \ do { \
__VA_OPT__(PRINTINTERR(__VA_ARGS__);) \ __VA_OPT__(PRINTINTERR(__VA_ARGS__);) \
} while (0) } while (0)
#endif
/* /*
* If cond is true, return ERR. Also call print_error or * If cond is true, return ERR. Also call print_error or
@ -59,7 +41,7 @@
} \ } \
} while (0) } while (0)
#define ERRCHK_MSG_(x) INTERRMSG "'" x "'" #define ERRCHK_MSG_(x) "'" x "'"
#define ERRCHK_RET_MSG(cond, ...) \ #define ERRCHK_RET_MSG(cond, ...) \
ERRCHK_RET(cond, ERRCHK_MSG_(#cond) __VA_OPT__(": %s", ) __VA_ARGS__) ERRCHK_RET(cond, ERRCHK_MSG_(#cond) __VA_OPT__(": %s", ) __VA_ARGS__)
@ -69,8 +51,7 @@
ERRCHK_MSG_(#cond) __VA_OPT__(": %s", ) __VA_ARGS__) ERRCHK_MSG_(#cond) __VA_OPT__(": %s", ) __VA_ARGS__)
#define ERRCHK_RET_ERN(cond) ERRCHK_RET_MSG(cond, strerror(errno)) #define ERRCHK_RET_ERN(cond) ERRCHK_RET_MSG(cond, strerror(errno))
#define ERRCHK_GOTO_ERN(cond, ret, label) \ #define ERRCHK_GOTO_ERN(cond, ret, label) ERRCHK_GOTO_MSG(cond, ret, label, strerror(errno))
ERRCHK_GOTO_MSG(cond, ret, label, strerror(errno))
/* /*
* Shortcut for ERRCHK_*_RET(expr != OK) * Shortcut for ERRCHK_*_RET(expr != OK)
@ -78,8 +59,6 @@
#define ERRCHK_RET_OK(e) ERRCHK_RET((e) != OK) #define ERRCHK_RET_OK(e) ERRCHK_RET((e) != OK)
#define ERRCHK_GOTO_OK(e, r, l) ERRCHK_GOTO((e) != OK, r, l) #define ERRCHK_GOTO_OK(e, r, l) ERRCHK_GOTO((e) != OK, r, l)
extern int err_internal_error;
enum { enum {
OK, OK,
ERR, ERR,
@ -87,5 +66,7 @@ enum {
void print_error(const char *error_msg); void print_error(const char *error_msg);
void print_errorf(const char *format, ...); void print_errorf(const char *format, ...);
void print_int_error(const char *file, unsigned long line, const char *msg);
void print_int_errorf(const char *file, unsigned long line, const char *format, ...);
#endif #endif