• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 574

18 Nov 2025 09:45PM UTC coverage: 51.773% (+0.006%) from 51.767%
574

push

github

PredatorCZ
move from logic errors

0 of 5 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

4131 of 7979 relevant lines covered (51.77%)

11430.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.45
/include/spike/except.hpp
1
/*  uni exception internal module
2
    part of uni module
3

4
    Copyright 2020-2021 Lukas Cone
5

6
    Licensed under the Apache License, Version 2.0 (the "License");
7
    you may not use this file except in compliance with the License.
8
    You may obtain a copy of the License at
9

10
        http://www.apache.org/licenses/LICENSE-2.0
11

12
    Unless required by applicable law or agreed to in writing, software
13
    distributed under the License is distributed on an "AS IS" BASIS,
14
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
    See the License for the specific language governing permissions and
16
    limitations under the License.
17
*/
18

19
#pragma once
20
#include <cinttypes>
21
#include <cstring>
22
#include <stdexcept>
23
#include <string>
24
#include <string_view>
25

26
namespace es {
27

28
class RuntimeError : public std::exception {
29
  const char *data;
30

31
public:
32
  explicit RuntimeError(const char *msg) : data(msg) {}
2✔
33
  const char *what() const noexcept override { return data; }
×
34
};
35

36
class ImplementationError : public std::exception {
37
  const char *data;
38

39
public:
UNCOV
40
  explicit ImplementationError(const char *msg) : data(msg) {}
×
41
  const char *what() const noexcept override { return data; }
×
42
};
43

44
class LengthError : public std::exception {
45
  const char *data;
46

47
public:
48
  explicit LengthError(const char *msg) : data(msg) {}
×
49
  const char *what() const noexcept override { return data; }
×
50
};
51

52
class FileNotFoundError : public std::runtime_error {
53
  using parent = std::runtime_error;
54

55
public:
56
  explicit FileNotFoundError() : parent("Couldn't open file.") {}
57
  explicit FileNotFoundError(std::string_view fileName)
2✔
58
      : parent("Couldn't open file: " + std::string(fileName)) {}
6✔
59
};
60

61
class FileInvalidAccessError : public std::runtime_error {
62
  using parent = std::runtime_error;
63

64
public:
65
  explicit FileInvalidAccessError() : parent("Couldn't access file.") {}
66
  explicit FileInvalidAccessError(std::string_view fileName)
1✔
67
      : parent("Couldn't access file: " + std::string(fileName)) {}
3✔
68
};
69

70
class InvalidHeaderError : public std::runtime_error {
71
  using parent = std::runtime_error;
72

73
public:
74
  static std::string DecompileFourCC(size_t magic, size_t size) {
75
    const char *rMagic = reinterpret_cast<const char *>(&magic);
76
    const size_t capSize =
77
        std::min(size, std::string_view ::traits_type::length(rMagic));
78
    bool isAlNum = true;
79

80
    for (size_t c = 0; c < capSize; c++) {
81
      if (!isalnum(rMagic[c])) {
82
        isAlNum = false;
83
        break;
84
      }
85
    }
86

87
    if (isAlNum) {
88
      return std::string{rMagic, capSize};
89
    } else {
90
      std::string retval;
91

92
      for (size_t c = 0; c < capSize; c++) {
93
        char buffer[8]{};
94
        snprintf(buffer, sizeof(buffer), "0x%X ", (unsigned char)rMagic[c]);
95
        retval.append(buffer);
96
      }
97

98
      return retval;
99
    }
100
  }
101

102
  explicit InvalidHeaderError() : parent("Invalid format.") {}
×
103
  InvalidHeaderError(std::string_view magic)
104
      : parent("Invalid format: " + std::string(magic)) {}
105
  template <typename T>
106
  InvalidHeaderError(T magic, size_t size = sizeof(T))
107
      : parent("Invalid format: " + DecompileFourCC(magic, size)) {}
108
};
109

110
class InvalidVersionError : public std::runtime_error {
111
  using parent = std::runtime_error;
112

113
public:
114
  explicit InvalidVersionError() : parent("Invalid version.") {}
115
  explicit InvalidVersionError(size_t version)
116
      : parent("Invalid version: " + std::to_string(version)) {}
117
};
118

119
class UnexpectedEOS : public RuntimeError {
120
  using parent = RuntimeError;
121

122
public:
123
  UnexpectedEOS() : parent("Unexpected end of stream.") {}
124
};
125
} // namespace es
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc