Skip to content

Releases

v1.1.0

Choose a tag to compare

@vasilesk vasilesk released this 01 Nov 19:49

Highlights

  • Zero dependencies. samber/lo has been replaced with the standard library.

  • log/slog integration. The new efmt.Attrs(err) returns the attached values as []slog.Attr, deduplicated and in a stable order:

    attrs := append(efmt.Attrs(err), slog.Any("error", err))
    logger.LogAttrs(ctx, slog.LevelError, "request failed", attrs...)

Bug fixes

  • Values from joined errors are no longer lost. Values are now collected from the whole error tree, including errors.Join and fmt.Errorf with several %w verbs. The traversal order is the same as in errors.Is.
  • Value[T] respects key shadowing. Before, if the outermost value for a key had a different type, Value[T] searched inner errors and could return a value that Values reports as overridden. Now it uses the same precedence as Values and returns false on a type mismatch.
  • New and Wrap copy the key-value slice. Before, changing a slice after passing it as kvs... silently changed the error that had already been created.

Documentation

  • Package documentation, with the key precedence rules described.
  • Testable examples, rendered on pkg.go.dev.
  • README sections on slog, key precedence and compatibility with the errors package.

Upgrade note

KeyValue is now a struct defined in efmt instead of an alias for lo.Entry[string, any]. Code that uses efmt.KV, .Key and .Value is not affected. Code that used efmt.KeyValue and lo.Entry interchangeably (for example, lo.FromEntries(efmt.ValuePairs(err))) needs a conversion or a switch to efmt.Values.

Full Changelog: v1.0.0...v1.1.0