From 6162f90610758c14e3d280869660e70e2857ccdd Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Sat, 28 Jan 2023 11:53:54 +0800 Subject: [PATCH] fix: don't crash when OTP_VERSION file is missing --- apps/emqx/src/emqx_vm.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/emqx/src/emqx_vm.erl b/apps/emqx/src/emqx_vm.erl index c1096f611..50582a2cc 100644 --- a/apps/emqx/src/emqx_vm.erl +++ b/apps/emqx/src/emqx_vm.erl @@ -400,7 +400,7 @@ compat_windows(Fun) -> end end. -%% @doc Return on which Eralng/OTP the current vm is running. +%% @doc Return on which Erlang/OTP the current vm is running. %% NOTE: This API reads a file, do not use it in critical code paths. get_otp_version() -> read_otp_version(). @@ -417,6 +417,8 @@ read_otp_version() -> %% running tests etc. OtpMajor = erlang:system_info(otp_release), OtpVsnFile = filename:join([ReleasesDir, OtpMajor, "OTP_VERSION"]), - {ok, Vsn} = file:read_file(OtpVsnFile), - Vsn + case file:read_file(OtpVsnFile) of + {ok, Vsn} -> Vsn; + {error, enoent} -> list_to_binary(OtpMajor) + end end.