asar coverage - build #265


src/asar/
File: src/asar/errors.cpp
Date: 2025-02-28 06:59:41
Lines:
30/30
100.0%
Functions:
7/7
100.0%
Branches:
13/22
59.1%

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 523 static void fmt_error(int whichpass, asar_error_id errid, const char* fmt, va_list args) {
12
3/6
✓ Branch 0 taken 523 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 267 times.
✓ Branch 3 taken 256 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
523 assert(errid >= 0 && errid < error_id_end);
13
14 267 char error_buffer[1024];
15
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 267 times.
523 vsnprintf(error_buffer, sizeof(error_buffer), fmt, args);
16
17
1/2
✓ Branch 0 taken 523 times.
✗ Branch 1 not taken.
523 error_interface((int)errid, whichpass, error_buffer);
18 523 }
19
20 // this is uncomfortably much to copy paste,,, but whatever
21 36 void asar_throw_error_impl_error_type_null(int whichpass, asar_error_id errid, const char* fmt, ...) {
22 36 va_list args; va_start(args, fmt);
23
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 fmt_error(whichpass, errid, fmt, args);
24 36 va_end(args);
25 36 }
26 442 void asar_throw_error_impl_error_type_block(int whichpass, asar_error_id errid, const char* fmt, ...) {
27 442 va_list args; va_start(args, fmt);
28
1/2
✓ Branch 0 taken 442 times.
✗ Branch 1 not taken.
442 fmt_error(whichpass, errid, fmt, args);
29 442 va_end(args);
30 442 throw errblock{};
31 }
32 37 void asar_throw_error_impl_error_type_line(int whichpass, asar_error_id errid, const char* fmt, ...) {
33 37 va_list args; va_start(args, fmt);
34
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 fmt_error(whichpass, errid, fmt, args);
35 37 va_end(args);
36 37 throw errline{};
37 }
38 8 void asar_throw_error_impl_error_type_fatal(int whichpass, asar_error_id errid, const char* fmt, ...) {
39 8 va_list args; va_start(args, fmt);
40
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 fmt_error(whichpass, errid, fmt, args);
41 8 va_end(args);
42 8 throw errfatal{};
43 }
44
45 436 const char* get_error_name(asar_error_id errid)
46 {
47
3/4
✓ Branch 0 taken 436 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 220 times.
✓ Branch 3 taken 216 times.
436 assert(errid >= 0 && errid < error_id_end);
48
49 436 const asar_error_mapping& error = asar_all_errors[errid];
50
51 436 return error.name;
52 }
53