Coverage Report

Created: 2025-06-15 00:57

/src/cmp_tool/lib/common/cmp_error.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file   cmp_error.c
3
 * @author Dominik Loidolt (dominik.loidolt@univie.ac.at)
4
 * @date   2024
5
 *
6
 * @copyright GPLv2
7
 * This program is free software; you can redistribute it and/or modify it
8
 * under the terms and conditions of the GNU General Public License,
9
 * version 2, as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
 * more details.
15
 *
16
 * @brief handling errors functions
17
 */
18
19
#include <stdint.h>
20
21
#include "cmp_error.h"
22
#include "cmp_error_list.h"
23
#include "../cmp_chunk.h"
24
25
26
/**
27
 * @brief tells if a result is an error code
28
 *
29
 * @param code  return value to check
30
 *
31
 * @returns non-zero if the code is an error
32
 */
33
34
unsigned int cmp_is_error(uint32_t code)
35
1.87M
{
36
1.87M
  return (code > CMP_ERROR(MAX_CODE));
37
1.87M
}
38
39
40
/**
41
 * @brief convert a function result into a cmp_error enum
42
 *
43
 * @param code  compression return value to get the error code
44
 *
45
 * @returns error code
46
 */
47
48
enum cmp_error cmp_get_error_code(uint32_t code)
49
114k
{
50
114k
  if (cmp_is_error(code))
51
26.0k
    return (enum cmp_error)(0-code);
52
53
88.2k
  return CMP_ERROR_NO_ERROR;
54
114k
}
55
56
57
/**
58
 * @brief get a string describing an error code
59
 *
60
 * @param code  the error code to describe, obtain with cmp_get_error_code()
61
 *
62
 * @returns a pointer to a string literal that describes the error code.
63
 */
64
65
const char* cmp_get_error_string(enum cmp_error code)
66
0
{
67
#ifdef CMP_STRIP_ERROR_STRINGS
68
  (void)code;
69
  return "Error strings stripped";
70
#else
71
0
  static const char* const notErrorCode = "Unspecified error code";
72
0
  switch (code) {
73
0
  case CMP_ERROR_NO_ERROR:
74
0
    return "No error detected";
75
0
  case CMP_ERROR_GENERIC:
76
0
    return "Error (generic)";
77
0
  case CMP_ERROR_SMALL_BUFFER:
78
0
    return "Destination buffer is too small to hold the whole compressed data";
79
0
  case CMP_ERROR_DATA_VALUE_TOO_LARGE:
80
0
    return "Data value is larger than expected";
81
82
83
0
  case CMP_ERROR_PAR_GENERIC:
84
0
    return "Compression mode or model value or lossy rounding parameter is unsupported";
85
0
  case CMP_ERROR_PAR_SPECIFIC:
86
0
    return "Specific compression parameters or combination is unsupported";
87
0
  case CMP_ERROR_PAR_BUFFERS:
88
0
    return "Buffer related parameter is not valid";
89
0
  case CMP_ERROR_PAR_NULL:
90
0
    return "Pointer to the compression parameters structure is NULL";
91
0
  case CMP_ERROR_PAR_NO_MODEL:
92
0
    return "Model need for model mode compression";
93
94
0
  case CMP_ERROR_CHUNK_NULL:
95
0
    return "Pointer to the chunk is NULL. No data, no compression";
96
0
  case CMP_ERROR_CHUNK_TOO_LARGE:
97
0
    return "Chunk size too large";
98
0
  case CMP_ERROR_CHUNK_TOO_SMALL:
99
0
    return "Chunk size too small. Minimum size is the size of a collection header";
100
0
  case CMP_ERROR_CHUNK_SIZE_INCONSISTENT:
101
0
    return "Chunk size is not consistent with the sum of the sizes in the compression headers. Chunk size may be wrong?";
102
0
  case CMP_ERROR_CHUNK_SUBSERVICE_INCONSISTENT:
103
0
    return "The chunk contains collections with an incompatible combination of subservices";
104
105
0
  case CMP_ERROR_COL_SUBSERVICE_UNSUPPORTED:
106
0
    return "Unsupported collection subservice";
107
0
  case CMP_ERROR_COL_SIZE_INCONSISTENT:
108
0
    return "Inconsistency detected between the collection subservice and data length";
109
110
0
  case CMP_ERROR_ENTITY_NULL:
111
0
    return "Compression entity pointer is NULL";
112
0
  case CMP_ERROR_ENTITY_TOO_SMALL:
113
0
    return "Compression entity size is too small";
114
0
  case CMP_ERROR_ENTITY_HEADER:
115
0
    return "An error occurred while generating the compression entity header";
116
0
  case CMP_ERROR_ENTITY_TIMESTAMP:
117
0
    return "Timestamp too large for the compression entity header";
118
119
0
  case CMP_ERROR_INT_DECODER:
120
0
    return "Internal decoder error occurred";
121
0
  case CMP_ERROR_INT_DATA_TYPE_UNSUPPORTED:
122
0
    return "Internal error: Data type not supported";
123
0
  case CMP_ERROR_INT_CMP_COL_TOO_LARGE:
124
0
    return "Internal error: compressed collection to large";
125
126
0
  case CMP_ERROR_MAX_CODE:
127
0
  default:
128
0
    return notErrorCode;
129
0
    }
130
0
#endif
131
0
}
132
133
134
/**
135
 * @brief provides a readable string from a compression return value (useful for debugging)
136
 *
137
 * @param code  compression return value to describe
138
 *
139
 * @returns a pointer to a string literal that describes the error code.
140
 */
141
142
const char* cmp_get_error_name(uint32_t code)
143
0
{
144
0
  return cmp_get_error_string(cmp_get_error_code(code));
145
0
}