Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logging[Wip] #3001

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

pedromiguelmiranda
Copy link
Contributor

@pedromiguelmiranda pedromiguelmiranda commented Jan 14, 2025

Improved eth1 logging:

  • using nimbus-eth2 options
  • log file support removal
  • auto detection of tty, colour support and related.

Note
This currently failing due to lack of support in nim-json-serialization and nim-serialization.
eg, this code fails to compile on both clients:

type
  SomeDistinctType* = distinct uint64

type AnotherType* = object
  UsingType*: SomeDistinctType
(...)
let test = AnotherType(UsingType: SomeDistinctType(10))
info "distinct type", distinct_type_info = test

- log file support removal
- auto detection of tty, colour support and related.
@tersec
Copy link
Contributor

tersec commented Jan 18, 2025

Yeah, this is arguably a nim-json-serialization bug:

/home/runner/work/nimbus-eth1/nimbus-eth1/nimbus/common/common.nim(128, 5) template/generic instantiation of `info` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-chronicles/chronicles.nim(380, 10) template/generic instantiation of `log` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/nimbus/common/common.nim(134, 7) template/generic instantiation of `expandItIMPL` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-chronicles/chronicles/log_output.nim(835, 39) template/generic instantiation of `setProperty` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-chronicles/chronicles/log_output.nim(772, 10) template/generic instantiation of `[]=` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-chronicles/chronicles/log_output.nim(745, 17) template/generic instantiation of `writeField` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-json-serialization/json_serialization/writer.nim(94, 8) template/generic instantiation of `writeValue` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-json-serialization/json_serialization/writer.nim(387, 23) template/generic instantiation of `writeRecordValue` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-json-serialization/json_serialization/writer.nim(203, 8) template/generic instantiation of `enumInstanceSerializedFields` from here
/home/runner/work/nimbus-eth1/nimbus-eth1/vendor/nim-serialization/serialization/object_serialization.nim(48, 40) Error: type mismatch
Expression: fieldPairs(value)
  [1] value: uint64

Expected one of (first mismatch at [position]):
[1] iterator fieldPairs[S: tuple | object; T: tuple | object](x: S; y: T): tuple[
    key: string, a, b: RootObj]
[1] iterator fieldPairs[T: tuple | object](x: T): tuple[key: string, val: RootObj]

is because nim-json-serialization's writeValue only checks for SomeInteger, before fairly shortly assuming it has to be an object of some type, a heuristic which fails in the case of a distinct of SomeInteger:

  elif value is SomeInteger:      # this case gets skipped
    w.stream.writeText value

  elif value is SomeFloat:
    # TODO Implement writeText for floats
    #      to avoid the allocation here:
    append $value

  elif value is (seq or array or openArray) or
      (value is distinct and distinctBase(value) is (seq or array or openArray)):
    when value is distinct:
      w.writeArray(distinctBase value)
    else:
      w.writeArray(value)

  elif value is (distinct or object or tuple):
    mixin flavorUsesAutomaticObjectSerialization

    type Flavor = JsonWriter.Flavor
    const isAutomatic =
      flavorUsesAutomaticObjectSerialization(Flavor)

    when not isAutomatic:
      const typeName = typetraits.name(type value)
      {.error: "Please override writeValue for the " & typeName & " type (or import the module where the override is provided)".}

    when value is distinct:
      # it tries to do this, but this is inappropriate for a `distinct SomeInteger`
      writeRecordValue(w, distinctBase(value, recursive = false))

This only trigers when flavorUsesAutomaticObjectSerialization(Flavor), otherwise it will (more or less defensibly reasonable) report that it can't, in this case, serialize EthTime.

But when automatic serialization is enabled, this at least some kind of n-j-s issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants