Skip to content

[lldb-dap] Fix URL label and error code in DAPError #145010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lldb/tools/lldb-dap/DAPError.cpp
Original file line number Diff line number Diff line change
@@ -18,14 +18,12 @@ char DAPError::ID;
DAPError::DAPError(std::string message, std::error_code EC, bool show_user,
std::optional<std::string> url,
std::optional<std::string> url_label)
: m_message(message), m_ec(EC), m_show_user(show_user), m_url(url),
m_url_label(url_label) {}
: m_message(std::move(message)), m_ec(EC), m_show_user(show_user),
m_url(std::move(url)), m_url_label(std::move(url_label)) {}

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

std::error_code DAPError::convertToErrorCode() const {
return llvm::inconvertibleErrorCode();
}
std::error_code DAPError::convertToErrorCode() const { return m_ec; }

char NotStoppedError::ID;

2 changes: 1 addition & 1 deletion lldb/tools/lldb-dap/DAPError.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ class DAPError : public llvm::ErrorInfo<DAPError> {
const std::string &getMessage() const { return m_message; }
bool getShowUser() const { return m_show_user; }
const std::optional<std::string> &getURL() const { return m_url; }
const std::optional<std::string> &getURLLabel() const { return m_url; }
const std::optional<std::string> &getURLLabel() const { return m_url_label; }

private:
std::string m_message;
1 change: 1 addition & 0 deletions lldb/unittests/DAP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_lldb_unittest(DAPTests
DAPErrorTest.cpp
DAPTest.cpp
FifoFilesTest.cpp
Handler/DisconnectTest.cpp
37 changes: 37 additions & 0 deletions lldb/unittests/DAP/DAPErrorTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===-- DAPErrorTest.cpp---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "DAPError.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
#include <system_error>

using namespace lldb_dap;
using namespace llvm;

TEST(DAPErrorTest, DefaultConstructor) {
DAPError error("Invalid thread");

EXPECT_EQ(error.getMessage(), "Invalid thread");
EXPECT_EQ(error.convertToErrorCode(), llvm::inconvertibleErrorCode());
EXPECT_TRUE(error.getShowUser());
EXPECT_EQ(error.getURL(), std::nullopt);
EXPECT_EQ(error.getURLLabel(), std::nullopt);
}

TEST(DAPErrorTest, FullConstructor) {
auto timed_out = std::make_error_code(std::errc::timed_out);
DAPError error("Timed out", timed_out, false, "URL", "URLLabel");

EXPECT_EQ(error.getMessage(), "Timed out");
EXPECT_EQ(error.convertToErrorCode(), timed_out);
EXPECT_FALSE(error.getShowUser());
EXPECT_THAT(error.getURL(), testing::Optional<std::string>("URL"));
EXPECT_THAT(error.getURLLabel(), testing::Optional<std::string>("URLLabel"));
}