asar coverage - build #258


src/asar/
File: src/asar/errors.cpp
Date: 2025-02-24 21:47:11
Lines:
29/29
100.0%
Functions:
7/7
100.0%
Branches:
9/18
50.0%

Line Branch Exec Source
1 #include "asar.h"
2 #include <cassert>
3 #include <cstdarg>
4
5 #include "interface-shared.h"
6
7 #if defined(__clang__) || defined(__GNUC__)
8 // silences the Wformat-nonliteral
9 [[gnu::format(printf, 3, 0)]]
10 #endif
11 1355 static void fmt_error(int whichpass, asar_error_id errid, const char* fmt, va_list args) {
12
2/4
✓ Branch 0 taken 683 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 683 times.
✗ Branch 3 not taken.
683 assert(errid >= 0 && errid < error_id_end);
13
14 char error_buffer[1024];
15 1355 vsnprintf(error_buffer, sizeof(error_buffer), fmt, args);
16
17
1/2
✓ Branch 0 taken 683 times.
✗ Branch 1 not taken.
1355 error_interface((int)errid, whichpass, error_buffer);
18 1355 }
19
20 // this is uncomfortably much to copy paste,,, but whatever
21 108 void asar_throw_error_impl_error_type_null(int whichpass, asar_error_id errid, const char* fmt, ...) {
22 108 va_list args; va_start(args, fmt);
23
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 fmt_error(whichpass, errid, fmt, args);
24 108 va_end(args);
25 108 }
26 1114 void asar_throw_error_impl_error_type_block(int whichpass, asar_error_id errid, const char* fmt, ...) {
27 1114 va_list args; va_start(args, fmt);
28
1/2
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
1114 fmt_error(whichpass, errid, fmt, args);
29 1114 va_end(args);
30 1114 throw errblock{};
31 }
32 109 void asar_throw_error_impl_error_type_line(int whichpass, asar_error_id errid, const char* fmt, ...) {
33 109 va_list args; va_start(args, fmt);
34
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
109 fmt_error(whichpass, errid, fmt, args);
35 109 va_end(args);
36 109 throw errline{};
37 }
38 24 void asar_throw_error_impl_error_type_fatal(int whichpass, asar_error_id errid, const char* fmt, ...) {
39 24 va_list args; va_start(args, fmt);
40
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 fmt_error(whichpass, errid, fmt, args);
41 24 va_end(args);
42 24 throw errfatal{};
43 }
44
45 964 const char* get_error_name(asar_error_id errid)
46 {
47
2/4
✓ Branch 0 taken 484 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 484 times.
✗ Branch 3 not taken.
484 assert(errid >= 0 && errid < error_id_end);
48
49 484 const asar_error_mapping& error = asar_all_errors[errid];
50
51 964 return error.name;
52 }
53