-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLVM][Support] Add new CreateFileError functions #125906
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
[LLVM][Support] Add new CreateFileError functions #125906
Conversation
@llvm/pr-subscribers-llvm-support Author: Amr Hesham (AmrDeveloper) ChangesAdd new CreateFileError functions to create a StringError with the specified error code and prepend the file path to it Needed for: #125345 Full diff: https://github.com/llvm/llvm-project/pull/125906.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 90120156ec2ead..48e17aabc1afda 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -1404,6 +1404,22 @@ inline Error createFileError(const Twine &F, size_t Line, std::error_code EC) {
return createFileError(F, Line, errorCodeToError(EC));
}
+/// Create a StringError with the specified error code and prepend the file path to it.
+inline Error createFileError(const Twine &F, std::error_code EC,
+ const Twine &S) {
+ Error E = createStringError(EC, S);
+ return createFileError(F, std::move(E));
+}
+
+
+/// Create a StringError with the specified error code and prepend the file path to it.
+template <typename... Ts>
+inline Error createFileError(const Twine &F, std::error_code EC,
+ char const *Fmt, const Ts &...Vals) {
+ Error E = createStringError(EC, Fmt, Vals...);
+ return createFileError(F, std::move(E));
+}
+
Error createFileError(const Twine &F, ErrorSuccess) = delete;
/// Helper for check-and-exit error handling.
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 98d19e8d2a15a3..b84fd621f76d43 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -976,6 +976,14 @@ TEST(Error, FileErrorTest) {
handleAllErrors(std::move(FE6), [](std::unique_ptr<FileError> F) {
EXPECT_EQ(F->messageWithoutFileInfo(), "CustomError {6}");
});
+
+ Error FE7 = createFileError("file.bin", make_error_code(std::errc::invalid_argument), "invalid argument");
+ EXPECT_EQ(toString(std::move(FE7)), "'file.bin': invalid argument");
+
+ StringRef Argument = "arg";
+ Error FE8 = createFileError("file.bin", make_error_code(std::errc::invalid_argument),
+ "invalid argument '%s'", Argument.str().c_str());
+ EXPECT_EQ(toString(std::move(FE8)), "'file.bin': invalid argument 'arg'");
}
TEST(Error, FileErrorErrorCode) {
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Do you need me to merge for you?
Thank you, I can merge |
Add new CreateFileError functions to create a StringError with the specified error code and prepend the file path to it Needed for: llvm#125345 (cherry picked from commit 2464f4b)
Add new CreateFileError functions to create a StringError with the specified error code and prepend the file path to it Needed for: llvm#125345
Add new CreateFileError functions to create a StringError with the specified error code and prepend the file path to it Needed for: llvm#125345 (cherry picked from commit 2464f4b)
Add new CreateFileError functions to create a StringError with the specified error code and prepend the file path to it
Needed for: #125345