Jelajahi Sumber

Merge pull request #13996 from thalesmg/20241014-m-fix-print-inconsist-mapget

fix(conf cli): don't crash when diffing missing key
Thales Macedo Garitezi 1 tahun lalu
induk
melakukan
1d701a8c6a
2 mengubah file dengan 6 tambahan dan 3 penghapusan
  1. 5 3
      apps/emqx_conf/src/emqx_conf_cli.erl
  2. 1 0
      changes/ce/fix-13996.en.md

+ 5 - 3
apps/emqx_conf/src/emqx_conf_cli.erl

@@ -284,6 +284,8 @@ print(Json) ->
 
 print_hocon(Hocon) when is_map(Hocon) ->
     emqx_ctl:print("~ts~n", [hocon_pp:do(Hocon, #{})]);
+print_hocon(undefined) ->
+    emqx_ctl:print("No value~n", []);
 print_hocon({error, Error}) ->
     emqx_ctl:warning("~ts~n", [Error]).
 
@@ -811,8 +813,8 @@ print_inconsistent_conf(Keys, Target, Status, AllConfs) ->
         fun(Key) ->
             lists:foreach(
                 fun({Node, OtherConf}) ->
-                    TargetV = maps:get(Key, TargetConf),
-                    PrevV = maps:get(Key, OtherConf),
+                    TargetV = maps:get(Key, TargetConf, undefined),
+                    PrevV = maps:get(Key, OtherConf, undefined),
                     NodeTnxId = get_tnx_id(Node, Status),
                     Options = #{
                         key => Key,
@@ -855,7 +857,7 @@ print_inconsistent_conf(New, Old, Options) ->
         target := {Target, TargetTnxId},
         node := {Node, NodeTnxId}
     } = Options,
-    emqx_ctl:print("~ts(tnx_id=~w)'s ~s is diff from ~ts(tnx_id=~w).~n", [
+    emqx_ctl:print("~ts(tnx_id=~w)'s ~s is different from ~ts(tnx_id=~w).~n", [
         Node, NodeTnxId, Key, Target, TargetTnxId
     ]),
     emqx_ctl:print("~ts:~n", [Node]),

+ 1 - 0
changes/ce/fix-13996.en.md

@@ -0,0 +1 @@
+Fixed an occasional crash when attempting to fix diverging configurations with `emqx conf fix` and one of the nodes is missing a configuration key.