You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2001/10/17 11:56:45 UTC
Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
It is almost *always* wrong to use "except:" in a Python program. Seeing
that in some code should make you *very* suspicious. Sometimes, it can hide
some problems that you really want to see. In the case below, you're
catching it and throwing away the information -- the name of the exception
isn't even printed, let alone a traceback.
I don't know the code here, but I'd recommend thinking things through a
*few* times if you ever find yourself using "except:"
Cheers,
-g
On Tue, Oct 16, 2001 at 11:55:01AM -0500, sussman@tigris.org wrote:
> Author: sussman
> Date: 2001-10-16 16:54 GMT
> New Revision: 248
>
> Modified:
> trunk/subversion/tests/clients/cmdline/svntest/main.py
> Log:
>
> * main.py (run_one_test): catch *all* exceptions and return error.
>
>
> Modified: trunk/subversion/tests/clients/cmdline/svntest/main.py
> ==============================================================================
> --- OLD/trunk/subversion/tests/clients/cmdline/svntest/main.py Tue Oct 16 11:54:59 2001
> +++ NEW/trunk/subversion/tests/clients/cmdline/svntest/main.py Tue Oct 16 11:54:59 2001
> @@ -249,7 +249,11 @@
> print "There is no test", `n` + ".\n"
> return 1
> # Run the test.
> - error = test_list[n]()
> + try:
> + error = test_list[n]()
> + except:
> + print "caught an exception, returning error instead"
> + error = 1
> if error:
> print "FAIL:",
> else:
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: svn-help@subversion.tigris.org
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
Posted by "Eric S. Raymond" <es...@thyrsus.com>.
Ben Collins-Sussman <su...@collab.net>:
> So... should we simply be looking to trap a list of *particular*
> exceptions? Like all those that our code might be expected tot throw?
> And also, is there a way to catch an exception and *still* print the
> traceback before returning an error value?
Sample code:
except:
# Pass the exception upwards for debugging purposes
(exc_type, exc_value, exc_traceback) = sys.exc_info()
if exc_type != LiftException:
self.error("internal error on: " + line)
raise exc_type, exc_value, exc_traceback
--
<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>
Men trained in arms from their infancy, and animated by the love of liberty,
will afford neither a cheap or easy conquest.
-- From the Declaration of the Continental Congress, July 1775.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
Posted by Roman Neuhauser <ne...@mobil.cz>.
> To: Greg Stein <gs...@lyra.org>
> Cc: dev@subversion.tigris.org
> From: Ben Collins-Sussman <su...@collab.net>
> Date: 17 Oct 2001 08:25:19 -0500
> Subject: Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
>
> Greg Stein <gs...@lyra.org> writes:
>
> > I don't know the code here, but I'd recommend thinking things through a
> > *few* times if you ever find yourself using "except:"
>
> Well, here's the scenario.
>
> The main python routine loops over a list of tests, and runs each one.
> It does this by repeatedly calling a subroutine that executes exactly
> one test (a particular test number). This subroutine's job is to
> return a 1 or 0 to the main routine, indicating whether the test
> passed or failed. In the end, the main python routine remembers
> whether any tests failed.
>
> The problem is that we've defined particular kinds of execptions --
> SVNTreeUnequal, and others. Sometimes our code explicitly raises
> them. When this happens, python bombs out completely. We'd rather
> just have the test return an error code instead, so the next tests
> will run.
>
> So... should we simply be looking to trap a list of *particular*
> exceptions? Like all those that our code might be expected tot throw?
> And also, is there a way to catch an exception and *still* print the
> traceback before returning an error value?
How about make _all_ tests throw an exception isntead of a return
code? The tests could indicate what happened through error messages
this way, right?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
RE: Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
Posted by Bill Tutt <ra...@lyra.org>.
Of course there is!
See the docs on the traceback module. There's a routine or two related
to printing tracebacks.
FYI,
Bill
-----Original Message-----
From: Ben Collins-Sussman [mailto:sussman@collab.net]
Sent: Wednesday, October 17, 2001 6:25 AM
To: Greg Stein
Cc: dev@subversion.tigris.org
Subject: Re: svn commit: rev 248 -
trunk/subversion/tests/clients/cmdline/svntest
Greg Stein <gs...@lyra.org> writes:
> I don't know the code here, but I'd recommend thinking things through
a
> *few* times if you ever find yourself using "except:"
Well, here's the scenario.
The main python routine loops over a list of tests, and runs each one.
It does this by repeatedly calling a subroutine that executes exactly
one test (a particular test number). This subroutine's job is to
return a 1 or 0 to the main routine, indicating whether the test
passed or failed. In the end, the main python routine remembers
whether any tests failed.
The problem is that we've defined particular kinds of execptions --
SVNTreeUnequal, and others. Sometimes our code explicitly raises
them. When this happens, python bombs out completely. We'd rather
just have the test return an error code instead, so the next tests
will run.
So... should we simply be looking to trap a list of *particular*
exceptions? Like all those that our code might be expected tot throw?
And also, is there a way to catch an exception and *still* print the
traceback before returning an error value?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: svn commit: rev 248 - trunk/subversion/tests/clients/cmdline/svntest
Posted by Ben Collins-Sussman <su...@collab.net>.
Greg Stein <gs...@lyra.org> writes:
> I don't know the code here, but I'd recommend thinking things through a
> *few* times if you ever find yourself using "except:"
Well, here's the scenario.
The main python routine loops over a list of tests, and runs each one.
It does this by repeatedly calling a subroutine that executes exactly
one test (a particular test number). This subroutine's job is to
return a 1 or 0 to the main routine, indicating whether the test
passed or failed. In the end, the main python routine remembers
whether any tests failed.
The problem is that we've defined particular kinds of execptions --
SVNTreeUnequal, and others. Sometimes our code explicitly raises
them. When this happens, python bombs out completely. We'd rather
just have the test return an error code instead, so the next tests
will run.
So... should we simply be looking to trap a list of *particular*
exceptions? Like all those that our code might be expected tot throw?
And also, is there a way to catch an exception and *still* print the
traceback before returning an error value?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org