Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-23604

Incorrect zbxerr implementation.

XMLWordPrintable

    • 2

      zbxerr package implementing Zabbix error type in the plugin-support repo is wrong.

      Golangs practice of propagation errors up the call chain allows for wraping errors with a message at each call step to provide a context of "what went wrong". Another golang practice is comparing or casting the returned error to a certain error type / constant to get additional details only present on a specific error implementation or to check against a specific error constant.

      Currently zbxerr package supports none of the above-described behaviour. zbxerr package does provide wrapping, but the current implementation is wrong as it destroys the underlying error type.

      Additionally, Zabbix golang code has a practice of wrapping error returns with Zabbix's own error constants. This implementation is also wrong as comparing the wrapped error should match both the underlying error and Zabbix error constant.

      Implement the following

      • before implementing anythin new unit test the existing functionality. doing this before new changes allows easy checking if anything was broken
      • keep any existing exported types and functions/methods signatures unchanged, mark as deprecated if necessary.
      • utility functions
        • Errorf(fmtstr string, args ...any) error - create a new zabbix error type
        • Wrap(err error, msg string) error - wraps any error with a message
        • Wrapf(err error, msg string, args ..any) error - wrap any error with a message
        • WrapConst(err, constant error) error - wraps any error with any other error. (basically like errors.Join, but only for 2)
      • 3 error implementation
        • for errors created by WrapConst. type must have a method Unwrap() []error returning two elements
        • for error constants. the type must have a method Unwrap() error
        • wrapped errors with messages. method Unwrap() error
      • unit test everything confirming the following cases
        • errors.Is correctly matches the underlying error constant in wrapped errors
        • errors.Is correctly matches both the underlying error constant and the wrapped error constant
        • errors.As correctly type casts the underlying error

            rzvejs Rudolfs Zvejs
            rzvejs Rudolfs Zvejs
            Team INT
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: