[ZBX-23604] Incorrect zbxerr implementation. Created: 2023 Oct 25  Updated: 2024 Apr 10  Resolved: 2023 Dec 20

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent2 plugin (G)
Affects Version/s: None
Fix Version/s: 6.0.26rc1, 6.4.11rc1, 7.0.0alpha9, 7.0 (plan)

Type: Problem report Priority: Trivial
Reporter: Rudolfs Zvejs (Inactive) Assignee: Rudolfs Zvejs (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Team: Team INT
Story Points: 2

 Description   

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


 Comments   
Comment by Rudolfs Zvejs (Inactive) [ 2023 Dec 18 ]

Implemented in

Generated at Fri May 02 10:24:15 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.