microchip-pic-avr-tools / pymcuprog

a Python utility for programming various Microchip MCU devices using Microchip CMSIS-DAP based debuggers
MIT License
96 stars 22 forks source link

Return value 0 on error #29

Closed ArneRossius closed 1 year ago

ArneRossius commented 1 year ago

pymcuprog returns 0 when an error occurs during programming (e.g. when target disconnected from programmer), but return value should be nonzero for error.

Examples:

No error (return value is 0 -- correct):

$ pymcuprog -t uart -u /dev/ttyUSB1 -d attiny214 ping; echo $?
Connecting to SerialUPDI
Pinging device...
Ping response: 1E9120
Done.
0

Target disconnected (return value is still 0 -- wrong):

$ pymcuprog -t uart -u /dev/ttyUSB1 -d attiny214 ping; echo $?
Connecting to SerialUPDI
pymcuprog.pymcuprog - ERROR - Operation failed with PymcuprogError: UPDI initialisation failed
0

Wrong parameters (return value is 2 -- correct, it's nonzero):

$ pymcuprog foobar; echo $?
usage: pymcuprog [-h] [-d DEVICE] [-p PACKPATH] [-t TOOL] [-s SERIALNUMBER]
                 [-m MEMORY] [-o OFFSET] [-b BYTES] [-l LITERAL [LITERAL ...]]
                 [-f FILENAME] [-c CLK] [-u UART] [-i INTERFACE]
                 [-v {debug,info,warning,error,critical}] [-V] [-R] [--erase]
                 [--verify] [-x]
                 [-H {tool-toggle-power,user-toggle-power,simple-unsafe-pulse}] [-U]
                 [-C]
                 {ping,erase,read,write,verify,getvoltage,getsupplyvoltage,reboot-debugger,setsupplyvoltage,getusbvoltage,reset}
pymcuprog: error: argument action: invalid choice: 'foobar' (choose from 'ping', 'erase', 'read', 'write', 'verify', 'getvoltage', 'getsupplyvoltage', 'reboot-debugger', 'setsupplyvoltage', 'getusbvoltage', 'reset')
2
xedbg commented 1 year ago

Logged internally as DSG-5157. (Thanks for the detailed report)

xedbg commented 1 year ago

Fixed in 3.14