Skip to content

Conversation

@eivindj-nordic
Copy link
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

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
@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
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
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
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
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) {
}

Copy link
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
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
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
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

{
#if CONFIG_BLE_ADV_FAST_ADVERTISING
int err;
uint32_t err;
Copy link
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
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.

@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
LOG_ERR("Failed to start advertising, err %d", err);
nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST);
if (nrf_err) {
LOG_ERR("Failed to start advertising, nrf_error %#x", err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LOG_ERR("Failed to start advertising, nrf_error %#x", err);
LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err);

static int advertising_start(bool erase_bonds)
{
int err = 0;
uint32_t nrf_err = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
uint32_t nrf_err = 0;
uint32_t nrf_err = NRF_SUCCESS;


__cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_ERROR_INVALID_PARAM);
ret = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW);
TEST_ASSERT_EQUAL(-EINVAL, ret);
Copy link
Contributor

Choose a reason for hiding this comment

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

Name of test still ends with _einval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected, thanks!

Comment on lines +282 to +285
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe align the error description here and for the other functions.

Suggested change
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.

Copy link
Contributor Author

@eivindj-nordic eivindj-nordic Oct 24, 2025

Choose a reason for hiding this comment

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

There are mant places we don't do that, but use a single space. Let's discuss offline and agree on the format for the repo.

nrf_err = sd_ble_gap_addr_get(&device_addr);
if (nrf_err) {
LOG_ERR("Failed to get device GAP address, nrf_error %#x", nrf_err);
return NRF_ERROR_INVALID_ADDR;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only error returned by the sd_ble_gap_addr_get apart from NRF_SUCCESS. The nRF5 SDK seems to return the error directly from sd_ble_gap_addr_get here.

nrf_err = sd_ble_gap_device_name_get(&data[*offset + AD_DATA_OFFSET], &actual_length);
if (nrf_err) {
LOG_ERR("Failed to get device GAP name, nrf_error %#x", nrf_err);
return NRF_ERROR_INVALID_PARAM;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could maybe return nrf_err here. The nRF5 SDK returns the error directly from sd_ble_gap_device_name_get.

nrf_err = sd_ble_gap_appearance_get(&appearance);
if (nrf_err) {
LOG_ERR("Failed to get GAP appearance, nrf_error %#x", nrf_err);
return NRF_ERROR_INVALID_ADDR;
Copy link
Contributor

Choose a reason for hiding this comment

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

The nRF5 SDK seems to return directly from sd_ble_gap_appearance_get here.

@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
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
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
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.

Change error codes to nrf_errors.

Signed-off-by: Eivind Jølsgard <[email protected]>
@eivindj-nordic eivindj-nordic force-pushed the error_code_alignment_ble_adv branch from ff36289 to 9c3c4e3 Compare October 24, 2025 11:29
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.

4 participants