Skip to content

lib: bluetooth: ble_adv: change error codes to nrf_error#436

Merged
eivindj-nordic merged 1 commit into
nrfconnect:mainfrom
eivindj-nordic:error_code_alignment_ble_adv
Oct 30, 2025
Merged

lib: bluetooth: ble_adv: change error codes to nrf_error#436
eivindj-nordic merged 1 commit into
nrfconnect:mainfrom
eivindj-nordic:error_code_alignment_ble_adv

Conversation

@eivindj-nordic
Copy link
Copy Markdown
Contributor

Change error codes to nrf_errors.

This is the first PR for updating the error codes for BLE libraries. Starting with the ble_adv library.
Moving forward all non-BLE libraries and components will return errnos, while BLE related code as BLE services, libraries and the SoftDevice will return nrf_errors.

@eivindj-nordic eivindj-nordic self-assigned this Oct 22, 2025
@eivindj-nordic eivindj-nordic requested review from a team as code owners October 22, 2025 07:14
@github-actions github-actions Bot added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval. labels Oct 22, 2025
@github-actions
Copy link
Copy Markdown

You can find the documentation preview for this PR here.

@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch 3 times, most recently from c94cb69 to 6fc813d Compare October 22, 2025 07:22
Comment thread applications/firmware_loader/ble_mcumgr/src/main.c Outdated
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from 6fc813d to c2fa6b6 Compare October 22, 2025 08:01

if (err) {
LOG_ERR("Failed to initialize advertising, err %d", err);
if (nrf_err != NRF_SUCCESS) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to be this explicit? I think it's easier to read if (nrf_err)

Copy link
Copy Markdown
Contributor Author

@eivindj-nordic eivindj-nordic Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should for good practice, as we don't have full control over the nrf_error values (although in practice it is very unlikely that NRF_SUCCESS will change). It also makes a clear distinction between errnos and nrf_errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can safely stick to the simpler:

if (nrf_err) {
}


if (err) {
LOG_ERR("Failed to initialize advertising, err %d", err);
if (nrf_err != NRF_SUCCESS) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can safely stick to the simpler:

if (nrf_err) {
}

Comment thread include/nrf_error.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be part of it...

/* Check parameter consistency */
if (ble_adv_data->srv_list.service == NULL) {
return -EFAULT;
return NRF_ERROR_INVALID_PARAM;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NRF_ERROR_NULL

if (service_data->len > 0) {
if (service_data->data == NULL) {
return -EINVAL;
return NRF_ERROR_INVALID_PARAM;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NRF_ERROR_NULL when a check against NULL fails

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am think we should stick to what is returned in the nRF5 SDK here, and other similar places. If changed to NRF_ERROR_NULL, the retval description for NRF_ERROR_NULL would also need to change for function ble_adv_data_encode().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Not a big deal, _INVALID_PARAM also works fine considering that all these pointers are optional, and in this case data could be NULL, if len wasn't also 0. An argument can be made that the error is len being non-zero, instead of data being NULL :)

Comment thread lib/bluetooth/ble_adv/ble_adv.c Outdated
{
#if CONFIG_BLE_ADV_FAST_ADVERTISING
int err;
uint32_t err;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should decide whether we want to store nrf_error values into nrf_err or whether it can be called generically err where there is only one error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking about that as well. For now I've only updated in the samples where it collides.

Comment thread lib/bluetooth/ble_adv/ble_adv.c Outdated
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch 4 times, most recently from 031b124 to 89653ba Compare October 22, 2025 13:03
Comment thread applications/firmware_loader/ble_mcumgr/src/main.c Outdated
Comment thread samples/bluetooth/ble_hids_keyboard/src/main.c Outdated
Comment thread tests/lib/bluetooth/ble_adv/src/unity_test.c
Comment thread include/bm/bluetooth/ble_adv.h
Comment thread lib/bluetooth/ble_adv/ble_adv_data.c Outdated
Comment thread lib/bluetooth/ble_adv/ble_adv_data.c Outdated
Comment thread lib/bluetooth/ble_adv/ble_adv_data.c Outdated
Comment thread lib/bluetooth/ble_adv/ble_adv.c Outdated
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from 89653ba to ff36289 Compare October 24, 2025 07:15
@eivindj-nordic eivindj-nordic added this to the v1.0.0 milestone Oct 24, 2025
Comment thread lib/bluetooth/ble_adv/ble_adv.c Outdated
err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
if (err) {
nrf_err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
if (nrf_err != NRF_SUCCESS) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be checking explictly against NRF_SUCCESS, it creates lots of noise for nothing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this here, will update.

@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from ff36289 to 9c3c4e3 Compare October 24, 2025 11:29
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from 9c3c4e3 to d1c16d2 Compare October 27, 2025 11:10
Comment thread include/bm/bluetooth/ble_adv.h
Comment thread include/bm/bluetooth/ble_adv.h Outdated
Comment thread include/bm/bluetooth/ble_adv_data.h Outdated
Comment thread lib/bluetooth/ble_adv/ble_adv_data.c Outdated
if (service_data->len > 0) {
if (service_data->data == NULL) {
return -EINVAL;
return NRF_ERROR_INVALID_PARAM;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am think we should stick to what is returned in the nRF5 SDK here, and other similar places. If changed to NRF_ERROR_NULL, the retval description for NRF_ERROR_NULL would also need to change for function ble_adv_data_encode().

@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from d1c16d2 to 315ed52 Compare October 27, 2025 11:40
Copy link
Copy Markdown
Contributor

@anhmolt anhmolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the comments and I'm happy with this.

Comment thread include/bm/bluetooth/ble_adv.h Outdated
Comment thread include/bm/bluetooth/ble_adv.h Outdated
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from 315ed52 to aacb251 Compare October 29, 2025 08:45
@eivindj-nordic
Copy link
Copy Markdown
Contributor Author

Fix the comments and I'm happy with this.

Happily addressed.

@eivindj-nordic
Copy link
Copy Markdown
Contributor Author

@nrfconnect/ncs-eris @nrfconnect/ncs-bm-doc Please review.

Copy link
Copy Markdown
Contributor

@lemrey lemrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a small nit.

Comment thread samples/bluetooth/ble_cgms/src/main.c Outdated
if (service_data->len > 0) {
if (service_data->data == NULL) {
return -EINVAL;
return NRF_ERROR_INVALID_PARAM;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Not a big deal, _INVALID_PARAM also works fine considering that all these pointers are optional, and in this case data could be NULL, if len wasn't also 0. An argument can be made that the error is len being non-zero, instead of data being NULL :)

@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from aacb251 to f3bbe57 Compare October 29, 2025 12:10

* Updated the following libraries to return ``nrf_errors`` instead of ``errnos``:

* BLE Advertising library.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* BLE Advertising library.
* :ref:`lib_ble_adv`.

Comment thread include/bm/bluetooth/ble_adv.h Outdated
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from f3bbe57 to d7640af Compare October 30, 2025 07:47
Change error codes to nrf_errors.

Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from d7640af to 77a3ff2 Compare October 30, 2025 07:49
@eivindj-nordic eivindj-nordic merged commit e2641ff into nrfconnect:main Oct 30, 2025
10 checks passed
@eivindj-nordic eivindj-nordic deleted the error_code_alignment_ble_adv branch October 30, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants