From 1978e2d1ca467a34dd10f0589aee987bab693a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Thu, 11 Apr 2024 14:40:31 +0200 Subject: [PATCH] Make commit hash in system status fail-safe 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. --- src/mongoose_server_api.erl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index 187a9a772d..aa33ba53f4 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -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.", @@ -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(_) -> <<>>. + -spec get_cookie() -> {ok, iolist()}. get_cookie() -> {ok, atom_to_list(erlang:get_cookie())}.