bundlewrap icon indicating copy to clipboard operation
bundlewrap copied to clipboard

dict_to_toml() is not Fault-aware

Open Kunsi opened this issue 3 years ago • 1 comments

I'm using dict_to_toml() to generate a config file, which contains Faults. I noticed dict_to_toml() doesn't convert Faults to strings.

I have patched my local installation as follows, but i'm not sure wether that's the best solution. That's why i'm filing an issue instead of a pull request.

diff --git a/bundlewrap/utils/dicts.py b/bundlewrap/utils/dicts.py
index d03859b2..f1353273 100644
--- a/bundlewrap/utils/dicts.py
+++ b/bundlewrap/utils/dicts.py
@@ -43,13 +43,15 @@ ATOMIC_TYPES = {
 
 def dict_to_toml(dict_obj):
     toml_doc = toml_document()
-    for key, value in dict_obj.items():
+    for key, value in sorted(dict_obj.items()):
         if isinstance(value, tuple):
             toml_doc[key] = list(value)
         elif isinstance(value, set):
             toml_doc[key] = sorted(value)
         elif isinstance(value, dict):
             toml_doc[key] = dict_to_toml(value)
+        elif isinstance(value, Fault):
+            toml_doc[key] = str(value)
         else:
             toml_doc[key] = value
     return toml_doc

Kunsi avatar Apr 10 '21 14:04 Kunsi

Well, it's not that easy, since now we're resolving Faults too early :/

Kunsi avatar Apr 10 '21 14:04 Kunsi