comparison mercurial/hgweb/protocol.py @ 9694:8269fe2d48f6

hgweb: send proper error messages to the client Fixes a bug in protocol which caused an exception during exception handling in some cases on Windows. Also makes sure the server error message is correctly propagated to the client, instead of being thrown away.
author Sune Foldager <cryo@cyanite.org>
date Mon, 02 Nov 2009 10:20:04 +0100
parents 061eeb602354
children d193cc97c4e8
comparison
equal deleted inserted replaced
9693:c40a1ee20aa5 9694:8269fe2d48f6
179 finally: 179 finally:
180 lock.release() 180 lock.release()
181 except ValueError, inst: 181 except ValueError, inst:
182 raise ErrorResponse(HTTP_OK, inst) 182 raise ErrorResponse(HTTP_OK, inst)
183 except (OSError, IOError), inst: 183 except (OSError, IOError), inst:
184 filename = getattr(inst, 'filename', '')
185 # Don't send our filesystem layout to the client
186 if filename.startswith(repo.root):
187 filename = filename[len(repo.root)+1:]
188 else:
189 filename = ''
190 error = getattr(inst, 'strerror', 'Unknown error') 184 error = getattr(inst, 'strerror', 'Unknown error')
191 if inst.errno == errno.ENOENT: 185 if inst.errno == errno.ENOENT:
192 code = HTTP_NOT_FOUND 186 code = HTTP_NOT_FOUND
193 else: 187 else:
194 code = HTTP_SERVER_ERROR 188 code = HTTP_SERVER_ERROR
195 raise ErrorResponse(code, '%s: %s' % (error, filename)) 189 filename = getattr(inst, 'filename', '')
190 # Don't send our filesystem layout to the client
191 if filename and filename.startswith(repo.root):
192 filename = filename[len(repo.root)+1:]
193 text = '%s: %s' % (error, filename)
194 else:
195 text = error.replace(repo.root + os.path.sep, '')
196 raise ErrorResponse(code, text)
196 finally: 197 finally:
197 fp.close() 198 fp.close()
198 os.unlink(tempname) 199 os.unlink(tempname)
199 200
200 def stream_out(repo, req): 201 def stream_out(repo, req):