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

mendersoftware / mender / 2153096345

06 Nov 2025 08:09AM UTC coverage: 79.818%. Remained the same
2153096345

push

gitlab-ci

web-flow
Merge pull request #1844 from thall/correct-err-mgs

fix: use correct variable for error message

0 of 2 new or added lines in 1 file covered. (0.0%)

7811 of 9786 relevant lines covered (79.82%)

14021.44 hits per line

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

76.47
/src/artifact/v3/header/type_info.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 <artifact/v3/header/header.hpp>
16

17
#include <vector>
18

19
#include <common/expected.hpp>
20
#include <common/error.hpp>
21
#include <common/io.hpp>
22
#include <common/log.hpp>
23
#include <common/json.hpp>
24
#include <common/common.hpp>
25

26
#include <artifact/error.hpp>
27
#include <artifact/lexer.hpp>
28
#include <artifact/tar/tar.hpp>
29

30

31
namespace mender {
32
namespace artifact {
33
namespace v3 {
34
namespace header {
35

36
namespace type_info {
37

38
namespace expected = mender::common::expected;
39
namespace io = mender::common::io;
40
namespace error = mender::common::error;
41
namespace log = mender::common::log;
42
namespace json = mender::common::json;
43

44
ExpectedTypeInfo Parse(io::Reader &reader) {
160✔
45
        TypeInfo type_info;
320✔
46

47
        log::Trace("Parse(type-info)...");
320✔
48

49
        auto expected_json = json::Load(reader);
160✔
50

51
        if (!expected_json) {
160✔
52
                return expected::unexpected(parser_error::MakeError(
×
53
                        parser_error::Code::ParseError,
54
                        "Failed to parse the  sub-header JSON: " + expected_json.error().message));
×
55
        }
56

57
        const json::Json type_info_json = expected_json.value();
160✔
58
        type_info.verbatim = type_info_json;
160✔
59

60

61
        //
62
        // Parse the single payload_type key:value (required)
63
        //
64

65
        log::Trace("type-info: Parsing the payload type");
320✔
66

67
        auto expected_payload = type_info_json.Get("type");
160✔
68
        if (!expected_payload) {
160✔
69
                return expected::unexpected(parser_error::MakeError(
×
70
                        parser_error::Code::ParseError,
71
                        "Failed to get the type-info payload type JSON: " + expected_payload.error().message));
×
72
        }
73
        auto payload_type = expected_payload.value();
160✔
74
        if (payload_type.IsNull()) {
160✔
75
                type_info.type = "null";
6✔
76
        } else if (payload_type.IsString()) {
154✔
77
                type_info.type = payload_type.GetString().value();
308✔
78
        } else {
79
                return expected::unexpected(parser_error::MakeError(
×
80
                        parser_error::Code::ParseError,
81
                        "Failed to parse the type-info payload type JSON: "
82
                                + expected_payload.error().message));
×
83
        }
84

85
        log::Trace("type-info: Parsing the artifact_provides");
320✔
86

87
        //
88
        // artifact_provides (Optional)
89
        //
90

91
        auto expected_artifact_provides =
92
                type_info_json.Get("artifact_provides").and_then(json::ToKeyValueMap);
320✔
93
        if (!expected_artifact_provides
160✔
94
                && expected_artifact_provides.error().code != json::MakeError(json::KeyError, "").code) {
181✔
95
                return expected::unexpected(parser_error::MakeError(
×
96
                        parser_error::Code::ParseError,
97
                        "Failed to parse the type-info artifact_provides JSON: "
98
                                + expected_artifact_provides.error().message));
×
99
        }
100
        if (expected_artifact_provides) {
160✔
101
                type_info.artifact_provides = expected_artifact_provides.value();
153✔
102
        } else {
103
                log::Trace("No artifact_provides found in type-info");
14✔
104
        }
105

106

107
        //
108
        // artifact_depends (Optional)
109
        //
110
        log::Trace("type-info: Parsing the artifact_depends");
320✔
111

112
        auto expected_artifact_depends =
113
                type_info_json.Get("artifact_depends").and_then(json::ToKeyValueMap);
320✔
114
        if (!expected_artifact_depends
160✔
115
                && expected_artifact_depends.error().code != json::MakeError(json::KeyError, "").code) {
631✔
116
                return expected::unexpected(parser_error::MakeError(
×
117
                        parser_error::Code::ParseError,
118
                        "Failed to parse the type-info artifact_depends JSON: "
NEW
119
                                + expected_artifact_depends.error().message));
×
120
        }
121
        if (expected_artifact_depends) {
160✔
122
                type_info.artifact_depends = expected_artifact_depends.value();
3✔
123
        } else {
124
                log::Trace("No artifact_depends found in type-info");
314✔
125
        }
126

127
        //
128
        // clears_artifact_provides (Optional)
129
        //
130

131
        log::Trace("type-info: Parsing the clears_artifact_provides");
320✔
132
        auto expected_clears_artifact_provides =
133
                type_info_json.Get("clears_artifact_provides").and_then(json::ToStringVector);
320✔
134
        if (!expected_clears_artifact_provides
160✔
135
                && expected_clears_artifact_provides.error().code
160✔
136
                           != json::MakeError(json::KeyError, "").code) {
181✔
137
                return expected::unexpected(parser_error::MakeError(
×
138
                        parser_error::Code::ParseError,
139
                        "Failed to parse the type-info clears_artifact_depends JSON: "
NEW
140
                                + expected_clears_artifact_provides.error().message));
×
141
        }
142
        if (expected_clears_artifact_provides) {
160✔
143
                type_info.clears_artifact_provides = expected_clears_artifact_provides.value();
153✔
144
        } else {
145
                log::Trace("No artifact_clears_provides found in type-info");
14✔
146
        }
147

148
        log::Trace("Finished parsing the type-info..");
320✔
149

150
        return type_info;
160✔
151
}
152

153
} // namespace type_info
154
} // namespace header
155
} // namespace v3
156
} // namespace artifact
157
} // 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