~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/remote.py

Consistently raise errors from the server as ErrorFromSmartServer exceptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
        return self._combine_paths(self._path, relpath)
158
158
 
159
159
    def _call(self, method, *args):
160
 
        resp = self._call2(method, *args)
 
160
        try:
 
161
            resp = self._call2(method, *args)
 
162
        except errors.ErrorFromSmartServer, err:
 
163
            self._translate_error(err.error_tuple)
161
164
        self._translate_error(resp)
162
165
 
163
166
    def _call2(self, method, *args):
164
167
        """Call a method on the remote server."""
165
 
        return self._client.call(method, *args)
 
168
        try:
 
169
            return self._client.call(method, *args)
 
170
        except errors.ErrorFromSmartServer, err:
 
171
            self._translate_error(err.error_tuple)
166
172
 
167
173
    def _call_with_body_bytes(self, method, args, body):
168
174
        """Call a method on the remote server with body bytes."""
169
 
        return self._client.call_with_body_bytes(method, args, body)
 
175
        try:
 
176
            return self._client.call_with_body_bytes(method, args, body)
 
177
        except errors.ErrorFromSmartServer, err:
 
178
            self._translate_error(err.error_tuple)
170
179
 
171
180
    def has(self, relpath):
172
181
        """Indicate whether a remote file of the given name exists or not.
190
199
 
191
200
    def get_bytes(self, relpath):
192
201
        remote = self._remote_path(relpath)
193
 
        request = self.get_smart_medium().get_request()
194
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
195
 
        smart_protocol.call('get', remote)
196
 
        resp = smart_protocol.read_response_tuple(True)
 
202
        try:
 
203
            resp, response_handler = self._client.call_expecting_body('get', remote)
 
204
        except errors.ErrorFromSmartServer, err:
 
205
            self._translate_error(err.error_tuple, relpath)
197
206
        if resp != ('ok', ):
198
207
            smart_protocol.cancel_read_body()
199
 
            self._translate_error(resp, relpath)
200
 
        return smart_protocol.read_body_bytes()
 
208
            raise errors.UnexpectedSmartServerResponse(resp)
 
209
        return response_handler.read_body_bytes()
201
210
 
202
211
    def _serialise_optional_mode(self, mode):
203
212
        if mode is None:
306
315
                               limit=self._max_readv_combine,
307
316
                               fudge_factor=self._bytes_to_read_before_seek))
308
317
 
309
 
        request = self.get_smart_medium().get_request()
310
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
311
 
        smart_protocol.call_with_body_readv_array(
312
 
            ('readv', self._remote_path(relpath)),
313
 
            [(c.start, c.length) for c in coalesced])
314
 
        resp = smart_protocol.read_response_tuple(True)
 
318
        try:
 
319
            result = self._client.call_with_body_readv_array(
 
320
                ('readv', self._remote_path(relpath),),
 
321
                [(c.start, c.length) for c in coalesced])
 
322
            resp, response_handler = result
 
323
        except errors.ErrorFromSmartServer, err:
 
324
            self._translate_error(err.error_tuple)
315
325
 
316
326
        if resp[0] != 'readv':
317
327
            # This should raise an exception
318
328
            smart_protocol.cancel_read_body()
319
 
            self._translate_error(resp)
320
 
            return
 
329
            raise errors.UnexpectedSmartServerResponse(resp)
321
330
 
322
331
        # FIXME: this should know how many bytes are needed, for clarity.
323
 
        data = smart_protocol.read_body_bytes()
 
332
        data = response_handler.read_body_bytes()
324
333
        # Cache the results, but only until they have been fulfilled
325
334
        data_map = {}
326
335
        for c_offset in coalesced: