forked from bdring/FluidNC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bdring#1148 from bdring/UseStdError
Use std:error for ESP and FluidNC errors, for better error reporting
- Loading branch information
Showing
11 changed files
with
177 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 202f Mitch Bradley | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
// Wrapper to make std:error_code from ESP_IDF esp_err_t values | ||
|
||
#include "esp_error.hpp" // Adapter | ||
|
||
namespace esp_error { | ||
namespace detail { | ||
class category : public std::error_category { | ||
public: | ||
virtual const char* name() const noexcept override { return "esp_error"; } | ||
virtual std::string message(int value) const override { | ||
// Let the native function do the actual work | ||
return ::esp_err_to_name((esp_err_t)value); | ||
} | ||
}; | ||
} // namespace detail | ||
|
||
const std::error_category& category() { | ||
// The category singleton | ||
static detail::category instance; | ||
return instance; | ||
} | ||
} // namespace esp_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2022 Mitch Bradley | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
// Wrapper to make std:error_code from ESP_IDF esp_err_t values | ||
|
||
#include <esp_err.h> // ESP_IDF error definitions | ||
#include <system_error> | ||
|
||
namespace esp_error { | ||
const std::error_category& category(); | ||
inline std::error_code make_error_code(esp_err_t err) { return std::error_code(err, esp_error::category()); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "FluidError.hpp" | ||
|
||
namespace FluidErrorCategory { | ||
const char* error_names[] = { "None", "SDCard not configured" }; | ||
namespace detail { | ||
class category : public std::error_category { | ||
public: | ||
virtual const char* name() const noexcept override { return "FluidError"; } | ||
virtual std::string message(int value) const override { return error_names[(int)value]; } | ||
}; | ||
} | ||
const std::error_category& category() { | ||
// The category singleton | ||
static detail::category instance; | ||
return instance; | ||
} | ||
} | ||
|
||
std::error_code make_error_code(FluidError err) { | ||
return std::error_code(static_cast<int>(err), FluidErrorCategory::category()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <system_error> | ||
|
||
// The associated message strings are in FluidError.cpp | ||
enum class FluidError { None, SDNotConfigured }; | ||
|
||
std::error_code make_error_code(FluidError); | ||
|
||
// Declare that FluidError is a standard error code | ||
// This makes it possible to assign a FluidError | ||
// directly to std::error_code variable, e.g. | ||
// std::error_code ec = FluidError::SDNotConfigured | ||
|
||
namespace std { | ||
template <> | ||
struct is_error_code_enum<FluidError> : true_type {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.