ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

Provide very bare-bones minimal success/error codes for CAN API.

Open aentinger opened this issue 1 year ago • 5 comments

This is related to https://github.com/arduino/ArduinoCore-mbed/pull/956 as well as to https://github.com/arduino/ArduinoCore-mbed/issues/924 .

The underlying problem is that different HALs provide different errors and different error codes when it comes to any peripheral usage (though we concern ourselves with CAN in this PR).

I propose to add at least those two very generic error codes at this very moment with the aim to expand error codes (i.e. CAN_TX_FIFO_FULL) further in the future.

aentinger avatar Sep 20 '24 07:09 aentinger

Thoughts @facchinm ?

aentinger avatar Sep 20 '24 07:09 aentinger

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.53%. Comparing base (4a02bfc) to head (6c411fe).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #237   +/-   ##
=======================================
  Coverage   95.53%   95.53%           
=======================================
  Files          16       16           
  Lines        1075     1075           
=======================================
  Hits         1027     1027           
  Misses         48       48           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Sep 20 '24 08:09 codecov-commenter

Definitely agree on the concept. On the numbering, it really depends on the expected pattern to consume these values. Eg: while (!can.write()) could mean "keep trying until the error disappears", so CAN_ERROR_GENERIC should be 0 (which is also consistent with the Print.write API (returns the number of bytes actually written, so 0 bytes in case of error).

facchinm avatar Sep 20 '24 12:09 facchinm

Ciao @facchinm :coffee: :wave:

That's allright with me. It is a little bit at odds with the current error definition but I'd say we have a chance right now to create a clean API. What do you think (concerning possible API breakage)?

aentinger avatar Sep 23 '24 05:09 aentinger

What about adopting Print strategy and add setWriteError/getWriteError while returning 0 on failure?

facchinm avatar Sep 23 '24 07:09 facchinm