LOG_ERROR

Table of Contents

LOG_ERROR

Description

Writes an error-level log message. …[in] : Format string and arguments following printf-style syntax.

Success

Error message written to log output

Failure

Logging fails silently (output not guaranteed)

Usage example (Cross-references)

    /* starting of an object */                                                                                    \
    if (StrIterPeek(&si) != '[') {                                                                                 \
    LOG_ERROR("Invalid array start. Expected '['.");                                                           \
    si = saved_si;                                                                                             \
    break;                                                                                                     \
    if (expect_comma) {                                                                                        \
    if (StrIterPeek(&si) != ',') {                                                                         \
    LOG_ERROR("Expected ',' between values in array. Invalid JSON array.");                            \
    failed = true;                                                                                     \
    si     = saved_si;                                                                                 \
    /* if still no advancement in read position */                                                         \
    if (read_si.pos == si.pos) {                                                                           \
    LOG_ERROR("Failed to parse value. Invalid JSON.");                                                 \
    StrDeinit(&key);                                                                                   \
    failed = true;                                                                                     \
    if (!failed) {                                                                                                 \
    if (StrIterPeek(&si) != ']') {                                                                             \
    LOG_ERROR("Invalid end of array. Expected ']'.");                                                      \
    failed = true;                                                                                         \
    si     = saved_si;                                                                                     \
    /* starting of an object */                                                                                    \
    if (StrIterPeek(&si) != '{') {                                                                                 \
    LOG_ERROR("Invalid object start. Expected '{'.");                                                          \
    si = saved_si;                                                                                             \
    break;                                                                                                     \
    if (expect_comma) {                                                                                        \
    if (StrIterPeek(&si) != ',') {                                                                         \
    LOG_ERROR("Expected ',' after key/value pairs in object. Invalid JSON object.");                   \
    failed = true;                                                                                     \
    si     = saved_si;                                                                                 \
    read_si = JReadString(si, &key);                                                                           \
    if (read_si.pos == si.pos) {                                                                               \
    LOG_ERROR("Failed to read string key in object. Invalid JSON");                                        \
    StrDeinit(&key);                                                                                       \
    failed = true;                                                                                         \
    \
    if (StrIterPeek(&si) != ':') {                                                                             \
    LOG_ERROR("Expected ':' after key string. Failed to read JSON");                                       \
    StrDeinit(&key);                                                                                       \
    failed = true;                                                                                         \
    /* if still no advancement in read position */                                                         \
    if (read_si.pos == si.pos) {                                                                           \
    LOG_ERROR("Failed to parse value. Invalid JSON.");                                                 \
    StrDeinit(&key);                                                                                   \
    failed = true;                                                                                     \
    char c = StrIterPeek(&si);                                                                                 \
    if (c != '}') {                                                                                            \
    LOG_ERROR("Expected end of object '}' but found '{c}'", c);                                            \
    failed = true;                                                                                         \
    si     = saved_si;                                                                                     \
    SysDirEntry* SysDirEntryInitCopy(SysDirEntry* dst, SysDirEntry* src) {
    if (!dst || !src) {
    LOG_ERROR("invalid arguments.");
    return NULL;
    }
    SysDirEntry* SysDirEntryDeinitCopy(SysDirEntry* copy) {
    if (!copy) {
    LOG_ERROR("invalid arguments.");
    return NULL;
    }
    SysDirContents SysGetDirContents(const char* path) {
    if (!path) {
    LOG_ERROR("invalid arguments.");
    return (SysDirContents) {0};
    }
    StrInitStack(err, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &err);
    LOG_ERROR("opendir(\"{}\") failed : {}", path, err);
    });
    return (SysDirContents) {0};
    StrInitStack(err, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &err);
    LOG_ERROR("failed to open file: {}\n", err);
    });
    return -1;
    StrInitStack(err, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &err);
    LOG_ERROR("failed to get file size: {}\n", err);
    });
    CloseHandle(file);
    StrInitStack(err, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &err);
    LOG_ERROR("failed to get file size: {}\n", err);
    });
    return -1;
    Str* SysGetCurrentExecutablePath(Str* exe_path) {
    if (!exe_path) {
    LOG_ERROR("Invalid arguments: exe_path is NULL");
    return NULL;
    }
    DWORD len = GetModuleFileNameA(NULL, buffer, MAX_PATH);
    if (len == 0 || len >= MAX_PATH) {
    LOG_ERROR("Failed to get executable path or buffer too small");
    return NULL;
    }
    
    // Last resort fallback
    LOG_ERROR("Could not determine executable path, using fallback");
    *exe_path = StrInitFromZstr("unknown_executable");
    return exe_path;
    SysProcInfo* SysCreateProcess(const char* executable, Strs* argv, Strs* env) {
    if (!executable) {
    LOG_ERROR("Invalid executable path");
    return NULL;
    }
    SysProcInfo* proc_info = NEW(SysProcInfo);
    if (!proc_info) {
    LOG_ERROR("Failed to allocate process info");
    return NULL;
    }
    if (!success) {
    DWORD error = GetLastError();
    LOG_ERROR("CreateProcess failed with error {}", error);
    FREE(proc_info);
    return NULL;
    // starting of an object
    if (StrIterPeek(&si) != '{') {
    LOG_ERROR("Invalid object start. Expected '{'.");
    return saved_si;
    }
    if (expect_comma) {
    if (StrIterPeek(&si) != ',') {
    LOG_ERROR(
    "Expected ',' between key/value pairs in object. Invalid "
    "JSON object."
    read_si = JReadString(si, &key);
    if (read_si.pos == si.pos) {
    LOG_ERROR("Failed to read string key in object. Invalid JSON");
    StrDeinit(&key);
    return saved_si;
    
    if (StrIterPeek(&si) != ':') {
    LOG_ERROR("Expected ':' after key string. Failed to read JSON");
    StrDeinit(&key);
    return saved_si;
    // if still no advancement in read position
    if (read_si.pos == si.pos) {
    LOG_ERROR("Failed to parse value. Invalid JSON.");
    StrDeinit(&key);
    return saved_si;
    char c = StrIterPeek(&si);
    if (c != '}') {
    LOG_ERROR("Expected end of object '}' but found '{c}'", c);
    return saved_si;
    }
    // starting of an object
    if (StrIterPeek(&si) != '[') {
    LOG_ERROR("Invalid array start. Expected '['.");
    return saved_si;
    }
    if (expect_comma) {
    if (StrIterPeek(&si) != ',') {
    LOG_ERROR("Expected ',' between values in array. Invalid JSON array.");
    return saved_si;
    }
    // if no advancement in read position
    if (read_si.pos == si.pos) {
    LOG_ERROR("Failed to parse value. Invalid JSON.");
    return saved_si;
    }
    // end of array
    if (StrIterPeek(&si) != ']') {
    LOG_ERROR("Invalid end of array. Expected ']'.");
    return saved_si;
    }
    
    if (!str) {
    LOG_ERROR("Invalid str object to read into.");
    return si;
    }
    StrIterNext(&si);
    if (!StrIterRemainingLength(&si)) {
    LOG_ERROR("Unexpected end of string.");
    StrClear(str);
    return saved_si;
    // espaced unicode sequence
    case 'u' :
    LOG_ERROR(
    "No unicode support '{.6}'. Unicode sequence will be skipped.",
    LVAL(si.data + si.pos - 1)
    
    default :
    LOG_ERROR("Invalid JSON object key string.");
    StrClear(str);
    return saved_si;
    
    if (!num) {
    LOG_ERROR("Invalid number object.");
    return si;
    }
    case 'e' :
    if (has_exp) {
    LOG_ERROR("Invalid number. Multiple exponent indicators.");
    StrDeinit(&ns);
    return saved_si;
    case '.' :
    if (is_flt) {
    LOG_ERROR("Invalid number. Multiple decimal indicators.");
    StrDeinit(&ns);
    return saved_si;
    // +/- can only appear after an exponent
    if (!has_exp) {
    LOG_ERROR(
    "Invalid number. Exponent sign indicators '+' or '-' "
    "must appear after exponent 'E' or 'e' indicator."
    }
    if (has_exp_plus_minus) {
    LOG_ERROR(
    "Invalid number. Multiple '+' or '-' in Number. "
    "Expected only once after 'e' or 'E'."
    
    if (!ns.length) {
    LOG_ERROR("Failed to parse number. '{.8}'", LVAL(saved_si.data + saved_si.pos));
    StrDeinit(&ns);
    return saved_si;
    }
    if (end == ns.data) {
    LOG_ERROR("Failed to convert string to number.");
    StrDeinit(&ns);
    return saved_si;
    
    if (!val) {
    LOG_ERROR("Invalid pointer to integer. Don't know where to store.");
    return si;
    }
    
    if (si.pos == saved_si.pos) {
    LOG_ERROR("Failed to parse integer number.");
    return saved_si;
    }
    
    if (num.is_float) {
    LOG_ERROR("Failed to parse integer. Got floating point value.");
    return saved_si;
    }
    
    if (!val) {
    LOG_ERROR("Invalid pointer to float. Don't know where to store.");
    return si;
    }
    
    if (si.pos == saved_si.pos) {
    LOG_ERROR("Failed to parse floating point number");
    return saved_si;
    }
    
    if (!b) {
    LOG_ERROR("Invalid boolean pointer. Don't know where to store.");
    return si;
    }
    return si;
    }
    LOG_ERROR("Failed to read boolean value. Expected true. Invalid JSON");
    return saved_si;
    }
    return si;
    }
    LOG_ERROR("Failed to read boolean value. Expected false. Invalid JSON");
    return saved_si;
    }
    }
    
    LOG_ERROR("Failed to parse boolean value. Expected true/false. Invalid JSON");
    return saved_si;
    } else {
    return saved_si;
    } else {
    LOG_ERROR(
    "Insufficient string length to parse a boolean value. Unexpected "
    "end of input."
    
    if (!is_null) {
    LOG_ERROR("Invalid boolean pointer. Don't know where to store.");
    return si;
    }
    return si;
    }
    LOG_ERROR("Failed to read boolean value. Expected null. Invalid JSON");
    return saved_si;
    }
    return saved_si;
    } else {
    LOG_ERROR(
    "Insufficient string length to parse a boolean value. Unexpected "
    "end of input."
    
    if (si.pos == before_si.pos) {
    LOG_ERROR(
    "Failed to read boolean value. Expected true/false. Invalid "
    "JSON."
    
    if (si.pos == before_si.pos) {
    LOG_ERROR(
    "Failed to read boolean value. Expected true/false. Invalid "
    "JSON."
    
    if (si.pos == before_si.pos) {
    LOG_ERROR("Failed to read string value. Expected string. Invalid JSON.");
    return saved_si;
    }
    
    if (si.pos == before_si.pos) {
    LOG_ERROR("Failed to read number value. Expected a number. Invalid JSON.");
    return saved_si;
    }
    
    if (si.pos == before_si.pos) {
    LOG_ERROR("Failed to read object. Expected an object. Invalid JSON.");
    return saved_si;
    }
    
    if (si.pos == before_si.pos) {
    LOG_ERROR("Failed to read array. Expected an array. Invalid JSON.");
    return saved_si;
    }
    }
    
    LOG_ERROR("Failed to read value. Invalid JSON");
    return si;
    }
    StrInitStack(syserr, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &syserr);
    LOG_ERROR("Failed to get localtime : {}", syserr);
    });
    goto LOG_STREAM_FALLBACK;
    StrInitStack(syserr, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(e, &syserr);
    LOG_ERROR("Failed to open log file : {}", syserr);
    });
    goto LOG_STREAM_FALLBACK;
    bool ReadCompleteFile(const char *filename, char **data, size *file_size, size *capacity) {
    if (!filename || !data || !file_size || !capacity) {
    LOG_ERROR("invalid arguments.");
    return false;
    }
    i64 fsize = SysGetFileSize(filename);
    if (-1 == fsize) {
    LOG_ERROR("failed to get file size");
    return false;
    }
    StrInitStack(syserr, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(e, &syserr);
    LOG_ERROR("fopen() failed : {}", syserr);
    });
    StrInitStack(syserr, SYS_ERROR_STR_MAX_LENGTH, {
    SysStrError(errno, &syserr);
    LOG_ERROR("failed to read complete file. : {}", syserr);
    });
    
    default :
    LOG_ERROR("Invalid format specifier");
    return false;
    }
    
    if (pos < len) {
    LOG_ERROR(
    "Parsing format specifier ended, but more characters are left for parsing. Indicates invalid format "
    "specifier."
    // Error if no closing brace found
    if (brace_end >= fmt_len) {
    LOG_ERROR("Unclosed format specifier");
    return false;
    }
    // Check if we have enough arguments
    if (arg_idx >= argc) {
    LOG_ERROR("Not enough arguments for format string");
    return false;
    }
    var_width = 8;
    } else {
    LOG_ERROR(
    "Raw data writing can only be used for u8-64, i8-64, f32, f64. Either unsupported format or "
    "attempt to write a complex type."
    
    if (fmt_info.width > var_width) {
    LOG_ERROR(
    "Number of raw bytes to be written exceeds variable width. Excess data filled with zeroes."
    );
    }
    default : {
    LOG_ERROR("Unreachable code reached");
    return false;
    }
    }
    default : {
    LOG_ERROR("Unreachable code reached");
    return false;
    }
    continue;
    }
    LOG_ERROR("Unmatched closing brace");
    return false;
    } else {
    // Check if we used all arguments
    if (arg_idx < argc) {
    LOG_ERROR("Too many arguments for format string");
    return false;
    }
    if (remaining >= 2 && p[0] == '{' && p[1] == '{') {
    if (!in || *in != '{') {
    LOG_ERROR("Expected '{' in input");
    return NULL;
    }
    } else if (remaining >= 2 && p[0] == '}' && p[1] == '}') {
    if (!in || *in != '}') {
    LOG_ERROR("Expected '}' in input");
    return NULL;
    }
    
    if (remaining == 0 || *p != '}') {
    LOG_ERROR("Unmatched '{' in format string");
    return NULL;
    }
    char spec_buf[32] = {0};
    if (spec_len >= sizeof(spec_buf)) {
    LOG_ERROR("Format specifier too long");
    return NULL;
    }
    
    if (arg_index >= argc) {
    LOG_ERROR("More placeholders than arguments");
    return NULL;
    }
    FmtInfo fmt_info;
    if (!ParseFormatSpec(spec_buf, spec_len, &fmt_info)) {
    LOG_ERROR("Failed to parse format specifier");
    return NULL; // Error already logged by ParseFormatSpec
    }
    TypeSpecificIO* io = &argv[arg_index++];
    if (!io->reader) {
    LOG_ERROR("Missing reader function");
    return NULL;
    }
    }
    default : {
    LOG_ERROR("Invalid raw data read width specified. Must be one of 1, 2, 4 or 8.");
    return NULL;
    }
    var_width = 8;
    } else {
    LOG_ERROR(
    "Raw data reading can only be used for u8-64, i8-64, f32, f64. Either unsupported format or "
    "attempt to read a complex type."
    }
    default : {
    LOG_ERROR("Invalid raw data read width specified. Must be one of 1, 2, 4 or 8.");
    return NULL;
    }
    // Check if reading failed
    if (!next || next == in) {
    LOG_ERROR("Failed to read value for placeholder {}", LVAL(arg_index - 1));
    return NULL;
    }
    // Match exact character from format string
    if (!in || *in != *p) {
    LOG_ERROR(
    "Input '{.8}' does not match format string '{.8}'",
    LVAL(in ? in : "(null)"),
    Str err = StrInit();
    SysStrError(errno, &err);
    LOG_ERROR("Could not save file position for rollback: {}", err);
    StrDeinit(&err);
    }
    if (!(new_pos = StrReadFmtInternal(buffer.data, fmtstr, argv, argc))) {
    if (can_rollback) {
    LOG_ERROR("Parse failed, rolling back...");
    fsetpos(file, &start_pos);
    } else {
    fsetpos(file, &start_pos);
    } else {
    LOG_ERROR("Parse failed, and rollback not possible on non-seekable input");
    }
    }
    const char* s = *str;
    if (*s != '\\') {
    LOG_ERROR("ProcessEscape called on non-escape sequence");
    return 0;
    }
    s++;
    if (!isxdigit(s[0]) || !isxdigit(s[1])) {
    LOG_ERROR("Invalid hex escape sequence");
    return 0;
    }
    }
    default :
    LOG_ERROR("Invalid escape sequence '\\{c}'", s[0]);
    return 0;
    }
    // Check for empty input
    if (!*i) {
    LOG_ERROR("Empty input string");
    return i;
    }
    // If we get here with a quote, the string was unterminated
    if (quote) {
    LOG_ERROR("Unterminated quoted string");
    StrDeinit(s);
    return NULL;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse f64: empty input");
    return i;
    }
    // Validate the string is a proper floating point number
    if (!IsValidNumericString(&temp, true)) {
    LOG_ERROR("Invalid floating point format");
    StrDeinit(&temp);
    return start;
    // Use StrToF64 directly
    if (!StrToF64(&temp, v, NULL)) {
    LOG_ERROR("Failed to parse f64");
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse u8: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    u64 val;
    if (!StrToU64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse u8");
    StrDeinit(&temp);
    return start;
    // Check for overflow
    if (val > UINT8_MAX) {
    LOG_ERROR("Value {} exceeds u8 maximum ({})", val, UINT8_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse u16: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    u64 val;
    if (!StrToU64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse u16");
    StrDeinit(&temp);
    return start;
    // Check for overflow
    if (val > UINT16_MAX) {
    LOG_ERROR("Value {} exceeds u16 maximum ({})", val, UINT16_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse u32: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    u64 val;
    if (!StrToU64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse u32");
    StrDeinit(&temp);
    return start;
    // Check for overflow
    if (val > UINT32_MAX) {
    LOG_ERROR("Value {} exceeds u32 maximum ({})", val, UINT32_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse u64: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    // Use base 0 to let strtoul detect the base from prefix
    if (!StrToU64(&temp, v, NULL)) {
    LOG_ERROR("Failed to parse u64");
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse i8: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    i64 val;
    if (!StrToI64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse i8");
    StrDeinit(&temp);
    return start;
    // Check for overflow/underflow
    if (val > INT8_MAX || val < INT8_MIN) {
    LOG_ERROR("Value {} outside i8 range ({} to {})", val, INT8_MIN, INT8_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse i16: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    i64 val;
    if (!StrToI64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse i16");
    StrDeinit(&temp);
    return start;
    // Check for overflow/underflow
    if (val > INT16_MAX || val < INT16_MIN) {
    LOG_ERROR("Value {} outside i16 range ({} to {})", val, INT16_MIN, INT16_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse i32: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    i64 val;
    if (!StrToI64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse i32");
    StrDeinit(&temp);
    return start;
    // Check for overflow/underflow
    if (val > INT32_MAX || val < INT32_MIN) {
    LOG_ERROR("Value {} outside i32 range ({} to {})", val, INT32_MIN, INT32_MAX);
    StrDeinit(&temp);
    return start;
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse i64: empty input");
    return i;
    }
    (temp.data[1] == 'x' || temp.data[1] == 'X' || temp.data[1] == 'b' || temp.data[1] == 'B' ||
    temp.data[1] == 'o' || temp.data[1] == 'O')) {
    LOG_ERROR("Incomplete number format");
    StrDeinit(&temp);
    return start;
    // Validate the string is a proper number
    if (!IsValidNumericString(&temp, false)) {
    LOG_ERROR("Invalid numeric format");
    StrDeinit(&temp);
    return start;
    // Use base 0 to let strtoul detect the base from prefix
    if (!StrToI64(&temp, v, NULL)) {
    LOG_ERROR("Failed to parse i64");
    StrDeinit(&temp);
    return start;
    char* result = malloc(temp.length + 1);
    if (!result) {
    LOG_ERROR("Failed to allocate memory for string");
    StrDeinit(&temp);
    return i;
    // Check for empty input
    if (!*i) {
    LOG_ERROR("Empty input string");
    return i;
    }
    
    if (i == hex_start) {
    LOG_ERROR("Invalid hex format - no digits after 0x");
    return start;
    }
    StrParseConfig config = {.base = 16};
    if (!StrToU64(&hex_str, &value, &config)) {
    LOG_ERROR("Failed to parse hex value");
    StrDeinit(&hex_str);
    return start;
    
    if (i == oct_start) {
    LOG_ERROR("Invalid octal format - no digits after 0o");
    return start;
    }
    StrParseConfig config = {.base = 8};
    if (!StrToU64(&oct_str, &value, &config)) {
    LOG_ERROR("Failed to parse octal value");
    StrDeinit(&oct_str);
    return start;
    
    if (i == bin_start) {
    LOG_ERROR("Invalid binary format - expected 0s and 1s");
    return start;
    }
    // Check for empty string
    if (!*i) {
    LOG_ERROR("Failed to parse f32: empty input");
    return i;
    }
    // Validate the string is a proper floating point number
    if (!IsValidNumericString(&temp, true)) {
    LOG_ERROR("Invalid floating point format");
    StrDeinit(&temp);
    return start;
    f64 val;
    if (!StrToF64(&temp, &val, NULL)) {
    LOG_ERROR("Failed to parse f32");
    StrDeinit(&temp);
    return start;
    size n = vsnprintf(NULL, 0, fmt, args);
    if (!n) {
    LOG_ERROR("invalid size of final string.");
    return NULL;
    }
    
    if (!is_valid_base(config->base)) {
    LOG_ERROR("Invalid base: {}", config->base);
    return NULL;
    }
    
    if (!is_valid_base(config->base)) {
    LOG_ERROR("Invalid base: {}", config->base);
    return NULL;
    }
    
    if (config->precision > 17) {
    LOG_ERROR("Precision {} exceeds maximum (17)", config->precision);
    return NULL;
    }
    
    if (!value) {
    LOG_ERROR("NULL output pointer");
    return false;
    }
    u8 base = config->base;
    if (base != 0 && !is_valid_base(base)) {
    LOG_ERROR("Invalid base: {}", base);
    return false;
    }
    
    if (pos >= str->length) {
    LOG_ERROR("Empty string");
    return false;
    }
    if (IS_SPACE(str->data[pos]))
    break;
    LOG_ERROR("Invalid digit for base {}: {c}", base, str->data[pos]);
    return false;
    }
    // Check overflow
    if (result > (UINT64_MAX - digit) / base) {
    LOG_ERROR("Overflow");
    return false;
    }
    
    if (config->strict && pos < str->length) {
    LOG_ERROR("Extra characters after number");
    return false;
    }
    
    if (!have_digits) {
    LOG_ERROR("No valid digits found");
    return false;
    }
    
    if (!value) {
    LOG_ERROR("NULL output pointer");
    return false;
    }
    
    if (pos >= str->length) {
    LOG_ERROR("Empty string");
    return false;
    }
    if (negative) {
    if (unsigned_value > 9223372036854775808ULL) {
    LOG_ERROR("Overflow");
    return false;
    }
    } else {
    if (unsigned_value > 9223372036854775807ULL) {
    LOG_ERROR("Overflow");
    return false;
    }
    
    if (!value) {
    LOG_ERROR("NULL output pointer");
    return false;
    }
    
    if (pos >= str->length) {
    LOG_ERROR("Empty string");
    return false;
    }
    
    if (!have_exp_digits) {
    LOG_ERROR("Missing exponent digits");
    return false;
    }
    
    if (config->strict && pos < str->length) {
    LOG_ERROR("Extra characters after number");
    return false;
    }
    
    if (!have_digits) {
    LOG_ERROR("No valid digits found");
    return false;
    }
    
    if (!e.name.length) {
    LOG_ERROR("Invalid enum entry in 'entries' array. Entry without name.");
    abort();
    }
    
    if (to_from_str && !e.str.length) {
    LOG_ERROR("to_from_str is set to true but str value not provided for enum {}", e.name);
    abort();
    }
    "{} {}FromZstr(const char* zstr) {{\n"
    "    if(!zstr) {{\n"
    "        LOG_ERROR(\"Invalid string provided. Cannot convert to enum.\");\n"
    "        return {};\n"
    "    }}\n";
    FILE* elf = fopen(argv[1], "rb");
    if (!elf) {
    LOG_ERROR("Failed to open file for reading.");
    return 1;
    }
    void ProjectDeinit(Project* p) {
    if (!p) {
    LOG_ERROR("Invalid project object. Invalid arguments");
    abort();
    }
    &file_contents.capacity
    )) {
    LOG_ERROR("Failed to read \"{}\" source file.", file_path.data);
    continue;
    }
    VecDeinit(&file);
    } else {
    LOG_ERROR("Failed to read file");
    }
    return 0;

Share :

Related Posts

StrReadFmt

StrReadFmt Description Parse input string according to format string with rust-style placeholders, extracting values into provided arguments. This is a macro wrapper around StrReadFmtInternal.

Read More

WriteFmt

WriteFmt Description Write formatted output to the standard output stream (stdout). This is a convenience macro calling FWriteFmt with stdout.

Read More

ReadFmt

ReadFmt Description Read formatted input from the standard input stream (stdin). This is a convenience macro calling FReadFmt with stdin.

Read More