Repository navigation
fix(handler): make update_log_meta/1 a no-op outside a request - #140
Merged
Merged
Conversation
An authorization callback can now return
`{with_log_meta, LogMeta, Response}`. minirest merges `LogMeta` into
the log meta in the same way as the meta of a successful
authorization, and sends only `Response` to the client.
`update_log_meta/1` now does nothing and returns `ok` when the calling
process does not handle a minirest request.
zmstone
marked this pull request as ready for review
September 17, 2026 11:24
2 of 3 tasks
keynslug
reviewed
Sep 17, 2026
| %% that is not allowed to use the endpoint. `LogMeta' is merged into the log | ||
| %% meta the same way as the meta of a successful authorization. Only | ||
| %% `Response' is sent to the client. | ||
| take_auth_log_meta({with_log_meta, LogMeta, Response}) when is_map(LogMeta) -> |
Contributor
There was a problem hiding this comment.
My bad 🫠 I didn't realize that minirest_handler:update_log_meta/1 is already used quite extensively in the EMQX codebase. So the badmap fix should already be enough for the EMQX PR.
That said, maybe this API addition is not really necessary. But if it is, perhaps introduce #response{} record in the public API so that we don't need to invent special wrappers for such things?
Member
Author
There was a problem hiding this comment.
revert to only handle badmap in minirest.
`update_log_meta/1` is already the way emqx adds log meta, and it now works outside a request. Keep only that change.
keynslug
approved these changes
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
update_log_meta/1merged new meta into the meta of the current request. When the calling process did not handle a minirest request, the stored meta wasundefined, and the call raisedbadmap. For example, a unit test that calls an authorization callback directly hits this. Callers had to catch the error.update_log_meta/1now does nothing and returnsokin that case. It used to return the previous meta. The emqx callers ignore the return value.Motivation: emqx/emqx#18879 records the denied caller in the audit log from its authorization callback. With this change it can call
update_log_meta/1without catchingbadmap.Tests
t_update_log_meta_outside_request:update_log_meta/1returnsokand writes nothing outside a request.Release
emqx pins minirest 1.4.12 on dev-60 to dev-62 and 1.5.x on dev-63, dev-70 and master. emqx#18879 targets dev-60, so it needs a 1.4.x tag with this change. The emqx branches that pin 1.5.x need a 1.5.x tag.