What is wrong with 'try'?
ok({ok,R}) -> R;
ok(E) -> throw(E).
try
Server = ok(get_radius_host()),
Port = ok(get_radius_port()),
Secret = ok(get_radius_secret),
{ok,{Server,Port,Secret}}
catch throw:E ->
E
end
WARNING: UNTESTED CODE.
I'd be inclined to do something slightly different:
ok({ok,R}, F) -> F(R);
ok(E) -> E.
ok(get_radius_server(), fun (Server) ->
ok(get_radius_host(), fun (Port) ->
ok(get_radius_secret(), fun (Secret) ->
{ok,{Server,Port,Secret}}
end) end) end)
(which is rather like using >>= \x -> rather than 'do' in Haskell).
I would also be wondering whether it is possible for a non-OK result to be
ambiguous. Are there values for E that could have come from more than
one of these 'get_*' functions? Might the caller of your code care about
where the error came from?
I find myself wondering whether a simple
{ok,Server} = ...
{ok,Port} = ....
{ok,Secret} = ...
might not be the most idiomatic "let it crash" Erlang way of all.
There is some important context missing here.
* Why isn't "let it crash" the right answer here?
* Why should the caller be told that an error occurred but
in a possibly ambiguous way?
* Is there no other validation to be done?
* What do the surrounding comments say?