Skip to content

Returning the wrong type on trace/capture fn causes mulog to silently stop recording logs and traces #119

@2food

Description

@2food

Hi,

I often use trace with :capture identity like this:

(µ/trace :foo {:pairs   {:info :blabla}
               :capture identity}
    (do-stuff))

Which is nice, because you get whatever the result of the body was in the trace log.
However, I just discovered that if the body returns a single value, rather than a map (or coll). The trace silently fails to log anything. So this:

(µ/trace :foo {:pairs   {:info :blabla}
               :capture identity}
    (do (stuff)
        :single-thing))

Will not log anything. And, additionally, any logs nested inside the trace will also fail. So this:

(µ/trace :foo {:pairs   {:info :blabla}
               :capture identity}
    (do (µ/log :bar)
        :single-thing))

Does not log anything, and does not throw an error either. Even if the `µ/log' happens deeper down in the call-stack of the body.

I think this behavior is quite unfortunate. If returning a non-map value in the capture function is invalid, it should throw an error, or log one, or maybe write the log without the captured value, or something else. But failing silently is not good.

Of course, the simple workaround would be to always wrap the returned value in a map, like this:

(µ/trace :foo {:pairs   {:info :blabla}
               :capture (fn [r] {:result r})}
    (do (µ/log :bar)
        :single-thing))

And I see that the doc for µ/trace does specify that the capture fn should return a map, but people don't always read the docs 😄 And even when they do, mistakes still happen.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions