Skip to content

Increase verbosity of error serialization #9105

@locker

Description

@locker

Link to the design document

Currently, the __serialize error object method only prints the error message omitting all other potentially useful fields. We will change that so that __serialize will call the unpack error object method, which converts an error object to a table, so that the output includes all the payload fields, for example:

tarantool> box.error.new{type = 'MyError', message = 'Error!', foo = 42, bar = "abc"}
---
- trace:
  - file: '[string "x = box.error.new{type = ''MyError'', message = ..."]'
    line: 1
  foo: 42
  type: MyError
  message: Error!
  bar: abc
...

The error cause will be unpacked when serialized as well, for example:

tarantool> prev = box.error.new{type = 'MyError', message = 'A', foo = 42}
---
...

tarantool> box.error.new{type = 'MyError', message = 'B', bar = 'abc', prev = prev}
---
- prev:
    type: MyError
    message: B
    foo: 42
    trace:
    - file: '[string "e = box.error.new{type = ''MyError'', message = ..."]'
      line: 1
  type: MyError
  message: B
  bar: abc
  trace:
  - file: '[string "box.error.new{type = ''MyError'', message = ..."]'
    line: 1
...

The __tostring method will print the error message followed by a tab space (\t) and all the payload fields serialized as a JSON map, for example:

tarantool> tostring(box.error.new{type = 'MyError', message = 'Something wrong', foo = {1, 2, 3}}
---
- Something wrong    {"type":"MyError","file":"...","line":1;"foo":[1,2,3]}
...

If an error has a cause it’ll be printed on a separate line preceding the effect, for example:

tarantool> prev = box.error.new{'Error cause'}
---
...

tarantool> box.error.new{'Error effect', prev = prev}
---
- |-
  Error cause    {"file":"...","line":1}
  Error effect   {"file":"...","line":1}
...

(The output was generated with the yaml_pretty_multiline compatibility option set to “new”.)

Here’s an example how errors will look when logged with the standard Tarantool logger:

local log = require('log')

box.cfg{log = 'tarantool.log'}

local e = box.error.new{
    message = 'Error effect',
    prev = box.error.new{message = 'Error cause'},
}

log.info(e)
log.info(e.prev)
2023-05-16 17:13:40.753 [4065414] main/103/interactive/tarantool I> Error cause    {"file":"example.lua","line":7}
Error effect   {"file":"...","line":5}
2023-05-16 17:13:40.753 [4065414] main/103/interactive/tarantool I> Error cause    {"file":"example.lua","line":7}

Since this change may potentially break existing users, we’ll introduce the new compat module option box_error_serialize_verbose to revert to the old behavior.

Note

The syslog server may mask the new line (\n) character although this behavior may usually be turned off. Still, we probably need to update the built-in Tarantool logger to split multi-line messages if the syslog logger is used.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions