Expose more Zephyr Kconfigs for error handling (#1622)

* zephyr: make `ETL_DEBUG` default to on if Zephyr assertions are enabled

this is the more appropriate default: ETL_DEBUG controls some container assertions, so it should follow the Zephyr assertions by default

* zephyr: expose new error-checking configs

* zephyr: add Kconfig choices for error handling
This commit is contained in:
Eden Frosst 2026-10-16 06:55:25 -04:00 committed by GitHub
parent ea54954c54
commit 5fe4a6cbd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 4 deletions

View File

@ -3,6 +3,16 @@ if(CONFIG_ETL)
zephyr_link_libraries(etl::etl) zephyr_link_libraries(etl::etl)
zephyr_compile_definitions_ifdef(CONFIG_ETL_DEBUG ETL_DEBUG) zephyr_compile_definitions_ifdef(CONFIG_ETL_DEBUG ETL_DEBUG)
zephyr_compile_definitions_ifdef(CONFIG_ETL_CHECK_PUSH_POP ETL_CHECK_PUSH_POP)
zephyr_compile_definitions_ifdef(CONFIG_ETL_LOG_ERRORS ETL_LOG_ERRORS) zephyr_compile_definitions_ifdef(CONFIG_ETL_LOG_ERRORS ETL_LOG_ERRORS)
zephyr_compile_definitions_ifdef(CONFIG_ETL_USE_ASSERT_FUNCTION ETL_USE_ASSERT_FUNCTION)
zephyr_compile_definitions_ifdef(CONFIG_ETL_THROW_EXCEPTIONS ETL_THROW_EXCEPTIONS)
zephyr_compile_definitions_ifdef(CONFIG_ETL_NO_CHECKS ETL_NO_CHECKS)
zephyr_compile_definitions_ifdef(CONFIG_ETL_VERBOSE_ERRORS ETL_VERBOSE_ERRORS)
zephyr_compile_definitions_ifdef(CONFIG_ETL_MINIMAL_ERRORS ETL_MINIMAL_ERRORS)
zephyr_compile_definitions_ifdef(CONFIG_ETL_CHECK_PUSH_POP ETL_CHECK_PUSH_POP)
zephyr_compile_definitions_ifdef(CONFIG_ETL_CHECK_INDEX_OPERATOR ETL_CHECK_INDEX_OPERATOR)
zephyr_compile_definitions_ifdef(CONFIG_ETL_CHECK_EXTRA ETL_CHECK_EXTRA)
endif() endif()

View File

@ -8,12 +8,78 @@ if ETL
config ETL_DEBUG config ETL_DEBUG
bool "Build ETL with debugging checks" bool "Build ETL with debugging checks"
default y if DEBUG default y if ASSERT
choice ETL_ERROR_MODE
prompt "ETL error handling mode"
help
What ETL does when one of its checks fails.
config ETL_ASSERT_ERRORS
bool "Assert in ETL_DEBUG builds, otherwise ignore"
help
With ETL_DEBUG, a failed check calls assert(). Without it, nothing
is reported, but checks that guard an operation still skip it.
With ETL_LOG_ERRORS, a failed check calls the error handler instead,
with or without ETL_DEBUG.
config ETL_USE_ASSERT_FUNCTION
bool "Call a user assert function"
help
A failed check calls the function registered with
etl::set_assert_function(), and checks that guard an operation
still skip it. Until one is registered, it calls assert(false).
config ETL_THROW_EXCEPTIONS
bool "Throw an exception"
depends on CPP_EXCEPTIONS
help
A failed check throws an etl::exception.
config ETL_NO_CHECKS
bool "No checks"
help
Check conditions are not evaluated.
endchoice # ETL_ERROR_MODE
config ETL_LOG_ERRORS
bool "Call the ETL error handler"
depends on !ETL_USE_ASSERT_FUNCTION && !ETL_NO_CHECKS
help
A failed check calls the callback registered with
etl::error_handler::set_callback(). With ETL_THROW_EXCEPTIONS it
then throws; otherwise, checks that guard an operation still skip
it. With no callback registered, errors are discarded.
choice ETL_ERROR_DETAIL
prompt "ETL error detail level"
help
What information the etl::exception for a failed check carries,
whether it is thrown or passed to the error handler or assert
function. Unused when a failed check calls plain assert().
config ETL_TERSE_ERRORS
bool "Short error code only"
config ETL_VERBOSE_ERRORS
bool "Message, file and line"
config ETL_MINIMAL_ERRORS
bool "Nothing"
endchoice # ETL_ERROR_DETAIL
config ETL_CHECK_PUSH_POP config ETL_CHECK_PUSH_POP
bool "Enable push/pop checks in ETL" bool "Enable push/pop checks in ETL"
depends on !ETL_NO_CHECKS
config ETL_LOG_ERRORS config ETL_CHECK_INDEX_OPERATOR
bool "Call ETL error handler instead of assert" bool "Enable bounds checks on ETL operator[]"
depends on !ETL_NO_CHECKS
config ETL_CHECK_EXTRA
bool "Enable extra bounds and empty checks in ETL containers"
depends on !ETL_NO_CHECKS
endif # ETL endif # ETL