Skip to content

Commit b0263ab

Browse files
committed
[lldb-dap] Fix DAPError
1 parent 09e794c commit b0263ab

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

lldb/tools/lldb-dap/DAPError.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ char DAPError::ID;
1818
DAPError::DAPError(std::string message, std::error_code EC, bool show_user,
1919
std::optional<std::string> url,
2020
std::optional<std::string> url_label)
21-
: m_message(message), m_ec(EC), m_show_user(show_user), m_url(url),
22-
m_url_label(url_label) {}
21+
: m_message(std::move(message)), m_ec(EC), m_show_user(show_user),
22+
m_url(std::move(url)), m_url_label(std::move(url_label)) {}
2323

2424
void DAPError::log(llvm::raw_ostream &OS) const { OS << m_message; }
2525

26-
std::error_code DAPError::convertToErrorCode() const {
27-
return llvm::inconvertibleErrorCode();
28-
}
26+
std::error_code DAPError::convertToErrorCode() const { return m_ec; }
2927

3028
char NotStoppedError::ID;
3129

lldb/tools/lldb-dap/DAPError.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DAPError : public llvm::ErrorInfo<DAPError> {
3030
const std::string &getMessage() const { return m_message; }
3131
bool getShowUser() const { return m_show_user; }
3232
const std::optional<std::string> &getURL() const { return m_url; }
33-
const std::optional<std::string> &getURLLabel() const { return m_url; }
33+
const std::optional<std::string> &getURLLabel() const { return m_url_label; }
3434

3535
private:
3636
std::string m_message;

lldb/unittests/DAP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_unittest(DAPTests
2+
DAPErrorTest.cpp
23
DAPTest.cpp
34
FifoFilesTest.cpp
45
Handler/DisconnectTest.cpp

lldb/unittests/DAP/DAPErrorTest.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===-- DAPErrorTest.cpp
2+
//-------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "DAPError.h"
11+
#include "gmock/gmock.h"
12+
#include "gtest/gtest.h"
13+
#include <string>
14+
#include <system_error>
15+
16+
using namespace lldb_dap;
17+
using namespace llvm;
18+
19+
TEST(DAPErrorTest, DefaultConstructor) {
20+
DAPError error("Invalid thread");
21+
22+
EXPECT_EQ(error.getMessage(), "Invalid thread");
23+
EXPECT_EQ(error.convertToErrorCode(), llvm::inconvertibleErrorCode());
24+
EXPECT_TRUE(error.getShowUser());
25+
EXPECT_EQ(error.getURL(), std::nullopt);
26+
EXPECT_EQ(error.getURLLabel(), std::nullopt);
27+
}
28+
29+
TEST(DAPErrorTest, FullConstructor) {
30+
auto timed_out = std::make_error_code(std::errc::timed_out);
31+
DAPError error("Timed out", timed_out, false, "URL", "URLLabel");
32+
33+
EXPECT_EQ(error.getMessage(), "Timed out");
34+
EXPECT_EQ(error.convertToErrorCode(), timed_out);
35+
EXPECT_FALSE(error.getShowUser());
36+
EXPECT_THAT(error.getURL(), testing::Optional<std::string>("URL"));
37+
EXPECT_THAT(error.getURLLabel(), testing::Optional<std::string>("URLLabel"));
38+
}

0 commit comments

Comments
 (0)