Skip to content

Commit 83fefee

Browse files
committed
[lldb-dap] Fix URL label and error code in DAPError
1 parent 09e794c commit 83fefee

File tree

4 files changed

+42
-6
lines changed

4 files changed

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

0 commit comments

Comments
 (0)