Skip to content

Commit

Permalink
Make commit hash in system status fail-safe
Browse files Browse the repository at this point in the history
This hotfix is needed to make the build for the 6.2.1 release pass.
The tests were failing only for GH tags, because the commit hash was
not available.

For now - default to an empty string (as binary, to avoid '[]' output).
We could make the field optional in the future to clean this up.
  • Loading branch information
chrzaszcz committed Apr 11, 2024
1 parent 5f2bc39 commit 1978e2d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mongoose_server_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set_loglevel(Level) ->
{invalid_level, io_lib:format("Log level ~p does not exist.", [Level])}
end.

-spec status() -> {ok, {boolean(), iolist(), iolist(), iolist()}}.
-spec status() -> {ok, {boolean(), iolist(), iolist(), iodata()}}.
status() ->
{InternalStatus, ProvidedStatus} = init:get_status(),
String1 = io_lib:format("The node ~p is ~p. Status: ~p.",
Expand All @@ -28,13 +28,17 @@ status() ->
{false, String1 ++ " MongooseIM is not running in that node.",
"MongooseIM is not running in that node", "MongooseIM is not running in that node"};
{value, {_, _, Version}} ->
[Number | Rest] = string:tokens(Version, "-"),
{true,
String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]),
lists:nth(1, string:tokens(Version, "-")),
string:slice(lists:nth(3, string:tokens(Version, "-")), 1)}
Number,
get_commit_hash(Rest)}
end,
{ok, Result}.

get_commit_hash([_, "g" ++ Hash]) -> Hash;
get_commit_hash(_) -> <<>>.

Check warning on line 40 in src/mongoose_server_api.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_server_api.erl#L40

Added line #L40 was not covered by tests

-spec get_cookie() -> {ok, iolist()}.
get_cookie() ->
{ok, atom_to_list(erlang:get_cookie())}.
Expand Down

0 comments on commit 1978e2d

Please sign in to comment.