llvm-project/lldb/tools/lldb-dap/Handler/ResponseHandler.cpp
Jonas Devlieghere 66af4923ce
[lldb-dap] Refactor reverse request response handlers (NFC) (#128594)
This refactors the response handlers for reverse request to follow the
same architecture as the request handlers. With only two implementation
that might be overkill, but it reduces code duplication and improves
error reporting by storing the sequence ID. This PR also fixes an
unchecked Expected in the old callback for unknown sequence IDs.
2025-02-25 13:00:26 -06:00

36 lines
1.1 KiB
C++

//===-- ResponseHandler.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 "ResponseHandler.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
namespace lldb_dap {
void UnknownResponseHandler::operator()(
llvm::Expected<llvm::json::Value> value) const {
llvm::errs() << "unexpected response: ";
if (value) {
if (std::optional<llvm::StringRef> str = value->getAsString())
llvm::errs() << *str;
} else {
llvm::errs() << "error: " << llvm::toString(value.takeError());
}
llvm::errs() << '\n';
}
void LogFailureResponseHandler::operator()(
llvm::Expected<llvm::json::Value> value) const {
if (!value)
llvm::errs() << "reverse request \"" << m_command << "\" (" << m_id
<< ") failed: " << llvm::toString(value.takeError()) << '\n';
}
} // namespace lldb_dap