xodio / xod

XOD IDE
https://xod.io
GNU Affero General Public License v3.0
894 stars 119 forks source link

Remove ERR pulses from standard library nodes #1788

Closed nkrkv closed 5 years ago

nkrkv commented 5 years ago

First-class error support is coming to XOD. The standard library should use the new mechanism as it more flexible and because the standard library is an instance of how things should be done.

Currently, the following patches use ERR-pulses:

$ rg ERR -l workspace | xargs -n1 dirname | sort | uniq
...
workspace/__lib__/xod/common-hardware/adxl335-accelerometer
workspace/__lib__/xod/common-hardware/analog-sensor
workspace/__lib__/xod/common-hardware/button
workspace/__lib__/xod/common-hardware/dht11-thermometer
workspace/__lib__/xod/common-hardware/dht2x-thermometer
workspace/__lib__/xod/common-hardware/dhtxx-read-raw
workspace/__lib__/xod/common-hardware/ds1307-rtc-read
workspace/__lib__/xod/common-hardware/ds1307-rtc-write
workspace/__lib__/xod/common-hardware/ds18b20-thermometer
workspace/__lib__/xod/common-hardware/gp2y0a02-range-meter
workspace/__lib__/xod/common-hardware/gp2y0a21-range-meter
workspace/__lib__/xod/common-hardware/gp2y0a41-range-meter
workspace/__lib__/xod/common-hardware/h-bridge-dc-motor
workspace/__lib__/xod/common-hardware/hc-sr04-ultrasonic-range
workspace/__lib__/xod/common-hardware/hc-sr04-ultrasonic-time
workspace/__lib__/xod/common-hardware/l3g4200-gyro
workspace/__lib__/xod/common-hardware/l3gd20h-gyro
workspace/__lib__/xod/common-hardware/led
workspace/__lib__/xod/common-hardware/lis331dlh-accelerometer
workspace/__lib__/xod/common-hardware/lis331hh-accelerometer
workspace/__lib__/xod/common-hardware/lis3dh-accelerometer
workspace/__lib__/xod/common-hardware/lps331-barometer
workspace/__lib__/xod/common-hardware/pot
workspace/__lib__/xod/common-hardware/sd-log
workspace/__lib__/xod/common-hardware/servo
workspace/__lib__/xod/common-hardware/st-barometer-read-pressure-raw
workspace/__lib__/xod/common-hardware/st-barometer-read-tmp-raw
workspace/__lib__/xod/common-hardware/st-barometer-write-register
workspace/__lib__/xod/common-hardware/st-imu-generic-sensor
workspace/__lib__/xod/common-hardware/st-imu-read-xyz
workspace/__lib__/xod/common-hardware/st-imu-write-register
workspace/__lib__/xod/common-hardware/thermometer-tmp36
workspace/__lib__/xod/core/error
workspace/__lib__/xod/core/format-progress
workspace/__lib__/xod-dev/ds-rtc/read
workspace/__lib__/xod-dev/ds-rtc/rtc
workspace/__lib__/xod-dev/ds-rtc/write
workspace/__lib__/xod-dev/esp8266/close
workspace/__lib__/xod-dev/esp8266/connect
workspace/__lib__/xod-dev/esp8266/connect-wifi
workspace/__lib__/xod-dev/esp8266/http-request(esp8266-inet)
workspace/__lib__/xod-dev/esp8266/kick
workspace/__lib__/xod-dev/esp8266-mcu/connect
workspace/__lib__/xod-dev/esp8266-mcu/http-request(esp8266-mcu-inet)
workspace/__lib__/xod-dev/esp8266-mcu/open-tcp
workspace/__lib__/xod-dev/esp8266-mcu/read-byte
workspace/__lib__/xod-dev/esp8266-mcu/send
workspace/__lib__/xod-dev/esp8266/open-tcp
workspace/__lib__/xod-dev/esp8266/receive-one-byte
workspace/__lib__/xod-dev/esp8266/send
workspace/__lib__/xod-dev/esp8266/set-station-mode
workspace/__lib__/xod-dev/pn532-nfc/init
workspace/__lib__/xod-dev/pn532-nfc/nfc-scanner
workspace/__lib__/xod-dev/pn532-nfc/pair-tag
workspace/__lib__/xod-dev/pn532-nfc/read-page
workspace/__lib__/xod-dev/pn532-nfc/write-page
workspace/__lib__/xod-dev/sharp-irm/gp2y0a02-range-meter
workspace/__lib__/xod-dev/sharp-irm/gp2y0a21-range-meter
workspace/__lib__/xod-dev/sharp-irm/gp2y0a41-range-meter
workspace/__lib__/xod-dev/w5500/connect
workspace/__lib__/xod-dev/w5500/connect-blocking
workspace/__lib__/xod-dev/w5500/connect-manual
workspace/__lib__/xod-dev/w5500/connect-manual-blocking
workspace/__lib__/xod-dev/w5500/ethernet-shield
workspace/__lib__/xod-dev/w5500/http-request(w5500-inet)
workspace/__lib__/xod-dev/w5500/open-tcp
workspace/__lib__/xod-dev/w5500/send
workspace/__lib__/xod/gpio/analog-read
workspace/__lib__/xod/gpio/digital-read
workspace/__lib__/xod/gpio/digital-write
workspace/__lib__/xod/gpio/pwm-write
workspace/__lib__/xod/i2c/begin-transmission
workspace/__lib__/xod/i2c/end-transmission
workspace/__lib__/xod/i2c/read-byte
workspace/__lib__/xod/i2c/request
workspace/__lib__/xod/i2c/write-byte
workspace/__lib__/xod/net/http-get
workspace/__lib__/xod/net/http-post
workspace/__lib__/xod/net/http-request
workspace/__lib__/xod/uart/print
workspace/__lib__/xod/uart/read-byte
workspace/__lib__/xod/uart/read-bytes
workspace/__lib__/xod/uart/write-byte
...

Let’s replace the ERR’s with error raising.

Acceptance criteria

¹

$ rg ERR -l | xargs -n1 dirname | sort | uniq 
docs/guide/buses
docs/guide/http-get
docs/guide/i2c
docs/guide/rtc-example
docs/guide/sd-log-example
docs/guide/w5500-advanced
docs/guide/w5500-connect
docs/guide/wrapping-arduino-libraries
brusherru commented 5 years ago

I found some classes of errors. So here are error codes that I can propose to use (but not sure about numbers):

Probably we have to group it by classes (i2c, io, gpio, network, devices). And probably some hardware-specific errors should be at "user-land" space. For example, "No echo" error code of the ultrasonic range meter could have a number 101.

Moreover, "No echo" probably is not an error and should be left as an output pulse. The same thing with read-byte. Should it raise an error if there are no available bytes to read, or just pulse to the output pulse "NA" (Not Available)?

Also, the whole error system reminds me of error codes from bash scripts. So, probably, all error codes should be node specific. analog-read can't raise an error about internet connection like the any esp8266-mcu can't raise "Invalid port" error.

@nkrkv @evgenykochetkov @knopki Please, tell me your thoughts about it.