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

MikkelSchubert / adapterremoval / #111

30 Apr 2025 09:52AM UTC coverage: 67.045% (+0.06%) from 66.988%
#111

push

travis-ci

web-flow
fix misleading io error messages (#137)

In particular, errors without assosiated error codes would include
nonsensical error descriptions. The use of ios_base::failure is dropped,
since IO generally is not done using iostreams

2 of 8 new or added lines in 4 files covered. (25.0%)

9751 of 14544 relevant lines covered (67.04%)

3041.83 hits per line

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

78.05
/src/errors.cpp
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
// SPDX-FileCopyrightText: 2024 Mikkel Schubert <mikkelsch@gmail.com>
3
#include "errors.hpp"   // declarations
4
#include "strutils.hpp" // for log_escape
5
#include <array>        // for array
6
#include <cerrno>       // for errno
7
#include <cstdio>       // for sys_errlist, sys_nerr
8
#include <cstring>      // for strerror_r
9
#include <exception>    // for exception
10
#include <ostream>      // for ostream
11
#include <string>       // for string
12
#include <string_view>  // for string_view
13

14
namespace adapterremoval {
15

16
// The function signature of strerror_r depends on the libc used. Rather than
17
// attempting to match defines, simply select the appropriate wrapper based on
18
// the signature of the function
19
using glibc_strerror_r = char* (*)(int, char*, size_t);
20
using posix_strerror_r = int (*)(int, char*, size_t);
21
//! Recommended buffer size according to `strerror` man page
22
using strerror_buf = std::array<char, 1024>;
23

24
namespace {
25

26
[[maybe_unused]] std::string
27
strerror_r_wrapper(glibc_strerror_r f, int error_number)
1✔
28
{
29
  strerror_buf buf{};
1✔
30
  return f(error_number, buf.data(), buf.size());
3✔
31
}
32

33
[[maybe_unused]] std::string
34
strerror_r_wrapper(posix_strerror_r f, int error_number)
35
{
36
  strerror_buf buf{};
37
  if (f(error_number, buf.data(), buf.size())) {
38
    return "unknown error " + std::to_string(error_number);
39
  }
40

41
  return buf.data();
42
}
43

44
std::ostream&
45
format_exception(std::ostream& os,
3✔
46
                 std::string_view name,
47
                 const std::exception& value)
48
{
49
  return os << name << "{" << log_escape(value.what()) << "}";
9✔
50
}
51

52
} // namespace
53

54
std::string
55
format_io_error(const std::string& message, const int error_number)
1✔
56
{
57
  if (error_number) {
1✔
58
    std::ostringstream stream;
1✔
59
    stream << message << ": " << strerror_r_wrapper(::strerror_r, error_number);
2✔
60

61
    return stream.str();
1✔
62
  } else {
1✔
63
    return message;
×
64
  }
65
}
66

67
assert_failed::assert_failed(const std::string& what)
46✔
68
  : std::logic_error(what)
46✔
69
{
70
}
46✔
71

NEW
72
io_error::io_error(const std::string& message)
×
NEW
73
  : std::runtime_error(message)
×
74
{
75
}
76

77
io_error::io_error(const std::string& message, int error_number)
1✔
78
  : std::runtime_error(format_io_error(message, error_number))
2✔
79
{
80
}
1✔
81

82
gzip_error::gzip_error(const std::string& message)
×
83
  : io_error(message)
×
84
{
85
}
86

87
parsing_error::parsing_error(const std::string& message)
108✔
88
  : std::runtime_error(message)
108✔
89
{
90
}
108✔
91

92
serializing_error::serializing_error(const std::string& message)
8✔
93
  : std::runtime_error(message)
8✔
94
{
95
}
8✔
96

97
fastq_error::fastq_error(const std::string& message)
51✔
98
  : parsing_error(message)
51✔
99
{
100
}
51✔
101

102
std::ostream&
103
operator<<(std::ostream& os, const assert_failed& value)
1✔
104
{
105
  return format_exception(os, "assert_failed", value);
1✔
106
}
107

108
std::ostream&
109
operator<<(std::ostream& os, const io_error& value)
×
110
{
111
  return format_exception(os, "io_error", value);
×
112
}
113

114
std::ostream&
115
operator<<(std::ostream& os, const gzip_error& value)
×
116
{
117
  return format_exception(os, "gzip_error", value);
×
118
}
119

120
std::ostream&
121
operator<<(std::ostream& os, const parsing_error& value)
1✔
122
{
123
  return format_exception(os, "parsing_error", value);
1✔
124
}
125

126
std::ostream&
127
operator<<(std::ostream& os, const fastq_error& value)
1✔
128
{
129
  return format_exception(os, "fastq_error", value);
1✔
130
}
131

132
} // namespace adapterremoval
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