]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Nicer error for can't overwrite existing cassette
authorMarc Abramowitz <marc@marc-abramowitz.com>
Thu, 19 Dec 2013 21:55:19 +0000 (13:55 -0800)
committerKevin McCarthy <me@kevinmccarthy.org>
Fri, 20 Dec 2013 05:20:00 +0000 (19:20 -1000)
Raise CannotOverwriteExistingCassetteException rather than Exception.
Include cassette filename and record mode in error message.

vcr/stubs/__init__.py

index 801a93cc5a7f6de4a9c9613c5266d3ace78674ba..c02ac549c0c04b217910a4deb40a7bc2b3e9801b 100644 (file)
@@ -6,6 +6,10 @@ from cStringIO import StringIO
 from vcr.request import Request
 
 
+class CannotOverwriteExistingCassetteException(Exception):
+    pass
+
+
 def parse_headers(header_list):
     headers = "".join(header_list) + "\r\n"
     msg = HTTPMessage(StringIO(headers))
@@ -172,9 +176,10 @@ class VCRConnectionMixin:
             return VCRHTTPResponse(response)
         else:
             if self.cassette.write_protected:
-                raise Exception(
-                    "Can't overwrite existing cassette in \
-                     your current record mode."
+                raise CannotOverwriteExistingCassetteException(
+                    "Can't overwrite existing cassette (%r) in "
+                    "your current record mode (%r)."
+                        % (self.cassette._path, self.cassette.record_mode)
                 )
 
             # Otherwise, we should send the request, then get the response