Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:25
erlang
3111-stdlib-Add-error-return-value-for-init.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3111-stdlib-Add-error-return-value-for-init.patch of Package erlang
From ddfd7da15cd51cf5dccd71ad772a302449a5b73a Mon Sep 17 00:00:00 2001 From: Micael Karlberg <bmk@erlang.org> Date: Tue, 31 Jan 2023 10:15:19 +0100 Subject: [PATCH 1/3] [stdlib] Add error return value for init Add a new "legal" return value for Module:init/1 (for both gen_server and gen_statem); {error, Reason} This should have same effect as ignore, except that the return value should be '{error, Reason}' instead of 'ignore'. OTP-18423 --- lib/stdlib/src/gen_server.erl | 15 ++++++++++++--- lib/stdlib/src/gen_statem.erl | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl index d920aa9fcd..3f355a5b53 100644 --- a/lib/stdlib/src/gen_server.erl +++ b/lib/stdlib/src/gen_server.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2022. All Rights Reserved. +%% Copyright Ericsson AB 1996-2023. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -169,7 +169,7 @@ -callback init(Args :: term()) -> {ok, State :: term()} | {ok, State :: term(), timeout() | hibernate | {continue, term()}} | - {stop, Reason :: term()} | ignore. + {stop, Reason :: term()} | ignore | {error, Reason :: term()}. -callback handle_call(Request :: term(), From :: from(), State :: term()) -> {reply, Reply :: term(), NewState :: term()} | @@ -851,6 +851,13 @@ init_it(Starter, Parent, Name0, Mod, Args, Options) -> gen:unregister_name(Name0), proc_lib:init_ack(Starter, {error, Reason}), exit(Reason); + {ok, {error, _Reason} = ERROR} -> + %% The point of this clause is that we shall have a silent/graceful + %% termination. The error reason will be returned to the + %% 'Starter' ({error, Reason}), but *no* crash report. + gen:unregister_name(Name0), + proc_lib:init_ack(Starter, ERROR), + exit(normal); {ok, ignore} -> gen:unregister_name(Name0), proc_lib:init_ack(Starter, ignore), @@ -861,7 +868,8 @@ init_it(Starter, Parent, Name0, Mod, Args, Options) -> exit(Error); {'EXIT', Class, Reason, Stacktrace} -> gen:unregister_name(Name0), - proc_lib:init_ack(Starter, {error, terminate_reason(Class, Reason, Stacktrace)}), + ActualReason = terminate_reason(Class, Reason, Stacktrace), + proc_lib:init_ack(Starter, {error, ActualReason}), erlang:raise(Class, Reason, Stacktrace) end. init_it(Mod, Args) -> @@ -872,6 +880,7 @@ init_it(Mod, Args) -> Class:R:S -> {'EXIT', Class, R, S} end. + %%%======================================================================== %%% Internal functions %%%======================================================================== diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index e3fa14a8a8..39cba737ef 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2016-2022. All Rights Reserved. +%% Copyright Ericsson AB 2016-2023. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -97,6 +97,9 @@ start_ret/0, start_mon_ret/0]). +%% -define(DBG(T), erlang:display({{self(), ?MODULE, ?LINE, ?FUNCTION_NAME}, T})). + + %%%========================================================================== %%% Interface functions. %%%========================================================================== @@ -225,8 +228,9 @@ {ok, State :: StateType, Data :: DataType} | {ok, State :: StateType, Data :: DataType, Actions :: [action()] | action()} | - 'ignore' | - {'stop', Reason :: term()}. + 'ignore' | + {'stop', Reason :: term()} | + {'error', Reason :: term()}. %% Old, not advertised -type state_function_result() :: @@ -1056,6 +1060,13 @@ init_result( gen:unregister_name(ServerRef), proc_lib:init_ack(Starter, {error,Reason}), exit(Reason); + {error, _Reason} = ERROR -> + %% The point of this clause is that we shall have a *silent* + %% termination. The error reason will be returned to the + %% 'Starter' ({error, Reason}), but *no* crash report. + gen:unregister_name(ServerRef), + proc_lib:init_ack(Starter, ERROR), + exit(normal); ignore -> gen:unregister_name(ServerRef), proc_lib:init_ack(Starter, ignore), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor