================
@@ -96,16 +124,44 @@ Status Status::FromErrorStringWithFormat(const char 
*format, ...) {
   return Status(string);
 }
 
-llvm::Error Status::ToError() const {
-  if (Success())
-    return llvm::Error::success();
-  if (m_type == ErrorType::eErrorTypePOSIX)
-    return llvm::errorCodeToError(
-        std::error_code(m_code, std::generic_category()));
-  return llvm::createStringError(AsCString());
+Status Status::FromExpressionError(lldb::ExpressionResults result,
+                                   std::string msg) {
+  return Status(llvm::make_error<ExpressionError>(
+      std::error_code(result, expression_category()), msg));
 }
 
-Status::~Status() = default;
+/// Creates a deep copy of all known errors and converts all other
+/// errors to a new llvm::StringError.
+static llvm::Error cloneError(llvm::Error &error) {
+  llvm::Error result = llvm::Error::success();
+  llvm::consumeError(std::move(result));
+  llvm::visitErrors(error, [&](const llvm::ErrorInfoBase &error) {
+    if (error.isA<MachKernelError>())
+      result = llvm::make_error<MachKernelError>(error.convertToErrorCode());
+    else if (error.isA<Win32Error>())
+      result = llvm::make_error<Win32Error>(error.convertToErrorCode());
+    else if (error.isA<ExpressionError>())
+      result = llvm::make_error<ExpressionError>(error.convertToErrorCode(),
+                                                 error.message());
+    else
+      result =
+          llvm::createStringError(error.convertToErrorCode(), error.message());
----------------
JDevlieghere wrote:

I assume this works because we don't user Errors that are ErrorLists. But If we 
did, wouldn't the callback get called multiple times, resulting in the result 
getting overridden (and an unchecked-error assertion)?

https://github.com/llvm/llvm-project/pull/106774
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to