Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1248a536 authored by Jaideep Sharma's avatar Jaideep Sharma Committed by Mikhail Naganov
Browse files

liberror: Add logs for failed conversions/status checks

Add error logs for macros, if the conversions,
status checks fail, as in error case these macros
cause methods to exit/return without indicating
the potential errors.

Bug: 308706390
Test: build source tree

Change-Id: I608fbb0ece4b085ce9455e5a603bf4cdb07cf0cb
Merged-In: I608fbb0ece4b085ce9455e5a603bf4cdb07cf0cb
parent bb80b1cb
Loading
Loading
Loading
Loading
+41 −15
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@
#include <android-base/expected.h>
#include <log/log_main.h>

#pragma push_macro("LOG_TAG")
#undef LOG_TAG
#define LOG_TAG "MediaLibError"

/**
 * Useful macros for working with status codes and base::expected.
 *
@@ -53,14 +57,22 @@
#define VALUE_OR_RETURN(exp)                                                          \
    ({                                                                                \
        auto _tmp = (exp);                                                            \
        if (!_tmp.ok()) return ::android::base::unexpected(std::move(_tmp.error())); \
        if (!_tmp.ok()) {                                                             \
            ALOGE("Function: %s Line: %d Failed result (%s)", __FUNCTION__, __LINE__, \
                  errorToString(_tmp.error()).c_str());                               \
            return ::android::base::unexpected(std::move(_tmp.error()));              \
        }                                                                             \
        std::move(_tmp.value());                                                      \
    })

#define VALUE_OR_RETURN_STATUS(exp)                                                   \
    ({                                                                                \
        auto _tmp = (exp);                                                            \
        if (!_tmp.ok()) return std::move(_tmp.error()); \
        if (!_tmp.ok()) {                                                             \
            ALOGE("Function: %s Line: %d Failed result (%s)", __FUNCTION__, __LINE__, \
                  errorToString(_tmp.error()).c_str());                               \
            return std::move(_tmp.error());                                           \
        }                                                                             \
        std::move(_tmp.value());                                                      \
    })

@@ -73,10 +85,22 @@
    })

#define RETURN_IF_ERROR(exp)                                                \
    if (auto _tmp = (exp); !errorIsOk(_tmp)) return ::android::base::unexpected(std::move(_tmp));
    ({                                                                      \
        auto _tmp = (exp);                                                  \
        if (!errorIsOk(_tmp)) {                                             \
            ALOGE("Function: %s Line: %d Failed ", __FUNCTION__, __LINE__); \
            return ::android::base::unexpected(std::move(_tmp));            \
        }                                                                   \
    })

#define RETURN_STATUS_IF_ERROR(exp)                                         \
    if (auto _tmp = (exp); !errorIsOk(_tmp)) return _tmp;
    ({                                                                      \
        auto _tmp = (exp);                                                  \
        if (!errorIsOk(_tmp)) {                                             \
            ALOGE("Function: %s Line: %d Failed ", __FUNCTION__, __LINE__); \
            return _tmp;                                                    \
        }                                                                   \
    })

#define FATAL_IF_ERROR(exp)                                                                \
    {                                                                                      \
@@ -84,3 +108,5 @@
        LOG_ALWAYS_FATAL_IF(!errorIsOk(_tmp), "Function: %s Line: %d Failed result: (%s)", \
                            __FUNCTION__, __LINE__, errorToString(_tmp).c_str());          \
    }

#pragma pop_macro("LOG_TAG")