fluent-rs icon indicating copy to clipboard operation
fluent-rs copied to clipboard

debug_assert when variables are missing from args

Open nordzilla opened this issue 2 years ago • 1 comments

We have a desire at Mozilla to be alerted in debug contexts when arguments are intended to be formatted with a variable, but no values are given. See the following bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=1685180

I think it may be reasonable to add debug_assert calls upstream here. But given that I am not one of the original designers of Fluent, I want to get another opinion as well.

@zbraniecki do you have any thoughts?

nordzilla avatar Jul 29 '22 18:07 nordzilla

Hmm, I'm not sure. Missing variable is a runtime developer error which may happen. Crashing seems like a blunt tool to address the issue on the level of a library. I don't know any prior art of libraries that are meant to interplot variables and patterns and debug crash on missing runtime variable.

Could you, for Mozilla use case, look into errors reported from format* method and if there's "missing variable" then debug crash?

We seem to have similar reporting here already that adapts how we report errors depending on type of the build - https://searchfox.org/mozilla-central/source/intl/l10n/Localization.h#45 Would that suffice?

zbraniecki avatar Aug 01 '22 10:08 zbraniecki

This seems like it should happen on the Gecko binding side to me.

gregtatum avatar Nov 07 '22 14:11 gregtatum

This was implemented in the Gecko bindings.

gregtatum avatar Nov 21 '22 17:11 gregtatum