summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <mklishin@pivotal.io>2017-07-05 14:48:03 +0300
committerMichael Klishin <mklishin@pivotal.io>2017-07-05 14:48:03 +0300
commitf5bb52d66f8d2bb76bda13827d1155c90627c54c (patch)
treea226a2d3d457929a9609ef2818150865b95b754d /src
parent30f929375211909ec98faa16eeb7071b67488647 (diff)
downloadrabbitmq-server-git-f5bb52d66f8d2bb76bda13827d1155c90627c54c.tar.gz
Make rabbit_vhost:add/2 return an error when it fails
This propagates the error the caller, e.g. the CLI command or HTTP API handler.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_vhost.erl22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/rabbit_vhost.erl b/src/rabbit_vhost.erl
index 4dc2ec86d0..aed01bec73 100644
--- a/src/rabbit_vhost.erl
+++ b/src/rabbit_vhost.erl
@@ -27,8 +27,8 @@
-export([dir/1, msg_store_dir_path/1, msg_store_dir_wildcard/0]).
-export([delete_storage/1]).
--spec add(rabbit_types:vhost(), rabbit_types:username()) -> 'ok'.
--spec delete(rabbit_types:vhost(), rabbit_types:username()) -> 'ok'.
+-spec add(rabbit_types:vhost(), rabbit_types:username()) -> rabbit_types:ok_or_error(any()).
+-spec delete(rabbit_types:vhost(), rabbit_types:username()) -> rabbit_types:ok_or_error(any()).
-spec update(rabbit_types:vhost(), rabbit_misc:thunk(A)) -> A.
-spec exists(rabbit_types:vhost()) -> boolean().
-spec list() -> [rabbit_types:vhost()].
@@ -104,10 +104,20 @@ add(VHostPath, ActingUser) ->
{<<"amq.rabbitmq.trace">>, topic, true}]],
ok
end),
- ok = rabbit_vhost_sup_sup:start_on_all_nodes(VHostPath),
- rabbit_event:notify(vhost_created, info(VHostPath)
- ++ [{user_who_performed_action, ActingUser}]),
- R.
+ case rabbit_vhost_sup_sup:start_on_all_nodes(VHostPath) of
+ ok ->
+ rabbit_event:notify(vhost_created, info(VHostPath)
+ ++ [{user_who_performed_action, ActingUser}]),
+ R;
+ {error, {no_such_vhost, VHostPath}} ->
+ Msg = rabbit_misc:format("failed to set up vhost '~s': it was concurrently deleted!",
+ [VHostPath]),
+ {error, Msg};
+ {error, Reason} ->
+ Msg = rabbit_misc:format("failed to set up vhost '~s': ~p",
+ [VHostPath, Reason]),
+ {error, Msg}
+ end.
delete(VHostPath, ActingUser) ->
%% FIXME: We are forced to delete the queues and exchanges outside