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

mendersoftware / mender / 2502703403

05 May 2026 11:20PM UTC coverage: 81.442% (+0.02%) from 81.426%
2502703403

push

gitlab-ci

lhoward
fix: common/error: include <ostream> for operator<<(ostream&, string&)

src/common/error.cpp defines

    std::ostream &operator<<(std::ostream &os, const Error &err) {
        os << err.String();
        ...
    }

err.String() returns std::string, so this relies on the free
function operator<<(std::ostream&, const std::string&) being a
complete definition at the call site, not just a forward declaration.

error.cpp only includes <common/error.hpp>, which in turn includes
<string> and <system_error>. Under libstdc++ that chain happens to
drag in the full body of the string ostream operator, so the call
gets inlined and the link succeeds. Under libc++, <string> only
provides a forward declaration (marked _LIBCPP_HIDE_FROM_ABI); the
body lives in <ostream>/<__ostream/basic_ostream.h>. Without that
include, the compiler emits an out-of-line call to a hidden-
visibility symbol that never gets defined and the link fails:

  undefined reference to 'std::operator<<[abi:...]<char, ...>(
    basic_ostream<char,...>&, const basic_string<char,...>&)'

Include <ostream> explicitly so the definition is reachable regardless
of which C++ standard library is in use.

Signed-off-by: Luke Howard <lukeh@padl.com>

9185 of 11278 relevant lines covered (81.44%)

20238.8 hits per line

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

62.96
/src/common/error.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/error.hpp>
16

17
#include <cassert>
18

19
namespace mender {
20
namespace common {
21
namespace error {
22

23
const Error NoError = Error();
24

25
const CommonErrorCategoryClass CommonErrorCategory;
26

27
Error MakeError(ErrorCode code, const std::string &msg) {
177✔
28
        return Error(std::error_condition(code, CommonErrorCategory), msg);
177✔
29
}
30

31
const char *CommonErrorCategoryClass::name() const noexcept {
×
32
        return "CommonErrorCategory";
×
33
}
34

35
std::string CommonErrorCategoryClass::message(int code) const {
3✔
36
        switch (code) {
3✔
37
        case ErrorCodeNoError:
38
                return "No error";
×
39
        case ProgrammingError:
40
                return "Programming error, should not happen";
×
41
        case GenericError:
42
                return "Unspecified error code";
3✔
43
        case ExitWithFailureError:
44
                return "ExitWithFailureError";
×
45
        case ExitWithSuccessError:
46
                return "ExitWithSuccessError";
×
47
        }
48
        assert(false);
49
        return "Unknown";
×
50
}
51

52
std::ostream &operator<<(std::ostream &os, const Error &err) {
×
53
        os << err.String();
×
54
        return os;
×
55
}
56

57
Error Error::FollowedBy(const Error &err) const {
74✔
58
        if (*this == NoError) {
74✔
59
                return err;
19✔
60
        }
61
        if (err == NoError) {
55✔
62
                return *this;
30✔
63
        }
64

65
        Error new_err {*this};
25✔
66
        new_err.message += "; Then followed error: " + err.String();
25✔
67
        return new_err;
25✔
68
}
69

70
Error Error::WithContext(const std::string &context) const {
1,191✔
71
        if (*this == NoError) {
1,191✔
72
                return *this;
870✔
73
        }
74

75
        return Error(code, context + ": " + message);
642✔
76
}
77

78
} // namespace error
79
} // namespace common
80
} // namespace mender
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