Skip to content

Commit

Permalink
Refactor printing of errors from generated functions
Browse files Browse the repository at this point in the history
Print from generated code, and include function name

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
  • Loading branch information
oyvindronningstad committed Jan 2, 2024
1 parent 8cdebd0 commit e9ee55e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion samples/pet/src/pet_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ static bool decode_Pet(
|| (((*result).species_choice == Pet_species_dog_c) && ((1)))
|| (((*result).species_choice == Pet_species_other_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state))));

if (!tmp_result)
if (!tmp_result) {
zcbor_trace_file(state);
zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
} else {
zcbor_log("%s success\r\n", __func__);
}

return tmp_result;
}
Expand Down
6 changes: 5 additions & 1 deletion samples/pet/src/pet_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ static bool encode_Pet(
: (((*input).species_choice == Pet_species_other_c) ? ((zcbor_uint32_put(state, (3))))
: false))))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 3))));

if (!tmp_result)
if (!tmp_result) {
zcbor_trace_file(state);
zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
} else {
zcbor_log("%s success\r\n", __func__);
}

return tmp_result;
}
Expand Down
1 change: 0 additions & 1 deletion src/zcbor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ int zcbor_entry_function(const uint8_t *payload, size_t payload_len,
int err = zcbor_pop_error(state);

err = (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err;
zcbor_log("Return error: %d\r\n", err);
return err;
}

Expand Down
6 changes: 5 additions & 1 deletion zcbor/zcbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2631,8 +2631,12 @@ def render_function(self, xcoder, mode):
bool tmp_result = ({ body });
if (!tmp_result)
if (!tmp_result) {{
zcbor_trace_file(state);
zcbor_log("%s error: %s\\r\\n", __func__, zcbor_error_str(zcbor_peek_error(state)));
}} else {{
zcbor_log("%s success\\r\\n", __func__);
}}
return tmp_result;
}}""".replace(" \n", "") # call replace() to remove empty lines.
Expand Down

0 comments on commit e9ee55e

Please sign in to comment.