From 53cd9c4c3408b5f2e54e891baf471c0d774ea2cd Mon Sep 17 00:00:00 2001 From: nasr Date: Sat, 14 Mar 2026 21:40:32 +0000 Subject: feature(base): ascii colors, error framework ( ai help ). testing idea meta program. refactor --- source/base/base_error.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source/base/base_error.h') diff --git a/source/base/base_error.h b/source/base/base_error.h index e69de29..b2bb4c0 100644 --- a/source/base/base_error.h +++ b/source/base/base_error.h @@ -0,0 +1,47 @@ +/* base library internal logging system */ +#ifndef BASE_ERROR_H +#define BASE_ERROR_H + +#define error_at(msg) \ + do \ + { \ + os_write(STDERR_FD, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ + write_string(STDERR_FD, __FILE__); \ + write_string(STDERR_FD, ":"); \ + write_int(__LINE__); \ + write_string(STDERR_FD, " in "); \ + write_string(STDERR_FD, __func__); \ + write_string(STDERR_FD, ": "); \ + write_string(STDERR_FD, (msg)); \ + os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ + } while (0) + +#define fatal(msg) \ + do \ + { \ + error_at(msg); \ + _exit(1); \ + } while (0) + +#define assert_msg(expr, msg) \ + do \ + { \ + if (!(expr)) \ + { \ + fatal(msg); \ + } \ + } while (0) + +#define warn(msg) \ + do \ + { \ + os_write(STDERR_FD, YELLOW "[WARN] ", LEN(YELLOW "[WARN] ")); \ + write_string(STDERR_FD, __FILE__); \ + write_string(STDERR_FD, ":"); \ + write_int(__LINE__); \ + write_string(STDERR_FD, ": "); \ + write_string(STDERR_FD, (msg)); \ + os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ + } while (0) + +#endif /* BASE_ERROR_H */ -- cgit v1.3