@@ -15,6 +15,7 @@ local FlattenError = errors.new_class("FlattenError", {capture_stack = false})
1515local UnflattenError = errors .new_class (" UnflattenError" , {capture_stack = false })
1616local ParseOperationsError = errors .new_class (' ParseOperationsError' , {capture_stack = false })
1717local ShardingError = errors .new_class (' ShardingError' , {capture_stack = false })
18+ local GetSpaceError = errors .new_class (' GetSpaceError' )
1819local GetSpaceFormatError = errors .new_class (' GetSpaceFormatError' , {capture_stack = false })
1920local FilterFieldsError = errors .new_class (' FilterFieldsError' , {capture_stack = false })
2021local NotInitializedError = errors .new_class (' NotInitialized' )
9798
9899function utils .get_space (space_name , replicasets )
99100 local replicaset = select (2 , next (replicasets ))
101+
102+ if replicaset == nil then
103+ return nil , GetSpaceError :new (
104+ ' The router returned empty replicasets: ' ..
105+ ' perhaps other instances are unavailable or you have configured only the router' )
106+ end
107+
108+ if replicaset .master == nil then
109+ local error_msg = string.format (
110+ ' The master was not found in replicaset %s, ' ..
111+ ' check status of the master and repeat the operation later' ,
112+ replicaset .uuid )
113+ return nil , GetSpaceError :new (error_msg )
114+ end
115+
116+ if replicaset .master .conn .error ~= nil then
117+ local error_msg = string.format (
118+ ' The connection to the master of replicaset %s is not valid: %s' ,
119+ replicaset .uuid , replicaset .master .conn .error )
120+ return nil , GetSpaceError :new (error_msg )
121+ end
100122 local space = replicaset .master .conn .space [space_name ]
101123
102124 return space
103125end
104126
105127function utils .get_space_format (space_name , replicasets )
106- local space = utils .get_space (space_name , replicasets )
128+ local space , err = utils .get_space (space_name , replicasets )
129+ if err ~= nil then
130+ return nil , GetSpaceFormatError :new (" An error occurred during the operation: %s" , err )
131+ end
107132 if space == nil then
108133 return nil , GetSpaceFormatError :new (" Space %q doesn't exist" , space_name )
109134 end
0 commit comments