Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions erlang_ls.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# erlang_ls.config
# Place this file in your project root directory

# Points directly to root folders for flat projects
src_dirs:
- "src/*"
- "test/*"

# Tracks your compiled external dependencies
deps_dirs:
- "_build/default/lib/*"
- "_build/test/lib/*"

# Maps paths for your header files (.hrl)
include_dirs:
- "include"
- "_build/default/lib/*/include"

# Real-time code analysis tools
diagnostics:
enabled:
- compiler
- crossref
disabled:
- dialyzer
- elvis

# Inline editor actions
lenses:
enabled:
- ct-run-test
- suggest-spec
54 changes: 46 additions & 8 deletions src/maps_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,9 @@ get_any(Keys, Map, Default) ->

put_path([], _, _) ->
error({badkey, []});

put_path(Path, Value, Map) when is_list(Path) ->
do_put_path(Path, Value, Map).



%% -----------------------------------------------------------------------------
%% @doc
%% @end
Expand Down Expand Up @@ -629,11 +626,6 @@ validate_update(Map0, Changes, Spec, Opts) when is_map(Changes), is_map(Spec), i
validate_update_error_list(Map0, Changes, Spec, Opts) when is_map(Changes), is_map(Spec), is_map(Opts) ->
maps:fold(fun(K, V, Accum) -> Accum++validate_update_key(K, V, Map0, Changes, Opts) end, [], Spec).






%% =============================================================================
%% PRIVATE
%% =============================================================================
Expand Down Expand Up @@ -670,9 +662,38 @@ maybe_get(Key, Map, Default) ->
do_put_path(Keys, Value, undefined) ->
do_put_path(Keys, Value, #{});

do_put_path(Keys, Value, [undefined]) ->
do_put_path(Keys, Value, #{});

do_put_path(Keys, Value, null) ->
do_put_path(Keys, Value, #{});

do_put_path(Keys, Value, [null]) ->
do_put_path(Keys, Value, #{});

do_put_path(Keys, Value, []) ->
do_put_path(Keys, Value, #{});

do_put_path(Path, Value, Bin) when is_binary(Bin) ->
try base64:decode(Bin) of
Decoded ->
case binary_to_term(Decoded) of
Map when is_map(Map) ->
do_put_path(Path, Value, Map);
L when is_list(L) ->
do_put_path(Path, Value, L);
_ ->
error({badmap, Bin})
end
catch
_:_ ->
error({badmap, Bin})
end;

do_put_path(Path, Value, List ) when is_list(List) ->
Map = try maps:from_list(List) catch _:_ -> #{} end,
do_put_path(Path, Value, Map);

do_put_path([Key], Value, Map) ->
maps:put(Key, Value, Map);

Expand All @@ -688,6 +709,23 @@ do_put_path([], _, Map) ->
do_put_path(Key, Value, Map) ->
maps:put(Key, Value, Map).

-ifdef(TEST).

-include_lib("eunit/include/eunit.hrl").

% Replicated this error
% 2026-05-06 12:30:01.569 [error] [<0.1430.0> magenta_riak_pool:transaction:51] error=error reason={badmap,<<"g2wAAAABZAAJdW5kZWZpbmVkag==">>} stacktrace=[{maps,put,[<<"enabled">>,true,<<"g2wAAAABZAAJdW5kZWZpbmVkag==">>],[]},{maps_utils,do_put_path,3,[{file,"/usr/src/app/_build/default/lib/maps_utils/src/maps_utils.erl"},{line,671}]},{maps_utils,do_put_path,3,[{file,"/usr/src/app/_build/default/lib/maps_utils/src/maps_utils.erl"},{line,674}]},{lists,foldl,3,[{file,"lists.erl"},{line,1267}]},{lists,map,2,[{file,"lists.erl"},{line,1243}]},{lists,map,2,[{file,"lists.erl"},{line,1243}]},{magenta_riak,handle_search,2,[{file,"/usr/src/app/_build/default/lib/magentalib/src/magenta_riak.erl"},{line,470}]},{magenta_riak_pool,transaction,1,[{file,"/usr/src/app/_build/default/lib/magentalib/src/magenta_riak_pool.erl"},{line,45}]}]
%

put_path_list_test() ->
#{<<"enabled">> := true } = do_put_path([<<"enabled">>], true, []),
#{<<"enabled">> := true, <<"key">> := value } = do_put_path([<<"enabled">>], true, [{<<"key">>, value}]).
put_path_binary_map_test() ->
% Base64 enconded list [undefined] should be converted to a map and then the path should be set
#{<<"enabled">> := true } = do_put_path([<<"enabled">>], true, <<"g2wAAAABZAAJdW5kZWZpbmVkag==">>),
#{<<"enabled">> := true } = do_put_path([<<"enabled">>], true, <<"g2wAAAABZAAJdW5kZWZpbmVkag==">>).
-endif.


%% @private
do_append_list_path(Keys, Value, undefined) ->
Expand Down