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

mendersoftware / mender / 1071875915

14 Nov 2023 11:46AM UTC coverage: 80.182% (+0.08%) from 80.107%
1071875915

push

gitlab-ci

kacf
chore: Get rid of direct comparisons with `Error::code`.

Such comparisons are dangerous, because if you don't also compare the
category, you can get false positives.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

12 of 12 new or added lines in 3 files covered. (100.0%)

79 existing lines in 9 files now uncovered.

6967 of 8689 relevant lines covered (80.18%)

9263.44 hits per line

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

44.44
/src/common/key_value_database.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/key_value_database.hpp>
16

17
#include <common/common.hpp>
18

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

23
namespace common = mender::common;
24

25
const KeyValueDatabaseErrorCategoryClass KeyValueDatabaseErrorCategory =
26
        KeyValueDatabaseErrorCategoryClass();
27

28
const char *KeyValueDatabaseErrorCategoryClass::name() const noexcept {
×
29
        return "KeyValueDatabaseErrorCategory";
×
30
}
31

UNCOV
32
string KeyValueDatabaseErrorCategoryClass::message(int code) const {
×
UNCOV
33
        switch (code) {
×
34
        case NoError:
35
                return "Success";
×
36
        case KeyError:
UNCOV
37
                return "Key error";
×
38
        case LmdbError:
39
                return "LMDB error";
×
40
        case AlreadyExistsError:
41
                return "Key already exists";
×
42
        default:
43
                return "Unknown";
×
44
        }
45
}
46

47
Error MakeError(ErrorCode code, const string &msg) {
1,000✔
48
        return Error(error_condition(code, KeyValueDatabaseErrorCategory), msg);
1,634✔
49
}
50

51
Error ReadString(Transaction &txn, const string &key, string &value_str, bool missing_ok) {
1,083✔
52
        auto ex_bytes = txn.Read(key);
1,083✔
53
        if (!ex_bytes) {
1,083✔
54
                if (!missing_ok || (ex_bytes.error().code != MakeError(KeyError, "").code)) {
2,536✔
55
                        return ex_bytes.error();
×
56
                }
57
        } else {
58
                value_str = common::StringFromByteVector(ex_bytes.value());
898✔
59
        }
60
        return error::NoError;
1,083✔
61
}
62

63
} // namespace key_value_database
64
} // namespace common
65
} // 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

© 2025 Coveralls, Inc