Repository: tapestry-5 Updated Branches: refs/heads/master 4f67dc7d4 -> b20ed0fae
TAP5-2486: make sure that IOOperation descripions appear in the operations trace if they throw an IOException #close Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/b20ed0fa Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/b20ed0fa Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/b20ed0fa Branch: refs/heads/master Commit: b20ed0fae7da0394caaa1609aaf3d60dda9b086a Parents: 4f67dc7 Author: Jochen Kemnade <[email protected]> Authored: Fri Aug 7 11:46:19 2015 +0200 Committer: Jochen Kemnade <[email protected]> Committed: Fri Aug 7 11:46:19 2015 +0200 ---------------------------------------------------------------------- .../ioc/internal/OperationTrackerImpl.java | 18 ++++++++- .../ioc/specs/OperationTrackerSpec.groovy | 42 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b20ed0fa/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java index 6bc462b..f523074 100644 --- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java +++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java @@ -119,6 +119,9 @@ public class OperationTrackerImpl implements OperationTracker } catch (Error ex) { return handleError(ex); + } catch (IOException ex) + { + return logAndRethrow(ex); } finally { handleFinally(); @@ -128,7 +131,6 @@ public class OperationTrackerImpl implements OperationTracker private void handleFinally() { operations.pop(); - // We've finally backed out of the operation stack ... but there may be more to come! if (operations.isEmpty()) @@ -187,6 +189,20 @@ public class OperationTrackerImpl implements OperationTracker throw ex; } + private <T> T logAndRethrow(IOException ex) throws IOException + { + if (!logged) + { + String[] trace = log(ex); + + logged = true; + + throw new OperationException(ex, trace); + } + + throw ex; + } + private String[] log(Throwable ex) { logger.error(ExceptionUtils.toMessage(ex)); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b20ed0fa/tapestry-ioc/src/test/groovy/ioc/specs/OperationTrackerSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/OperationTrackerSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/OperationTrackerSpec.groovy new file mode 100644 index 0000000..ba8c036 --- /dev/null +++ b/tapestry-ioc/src/test/groovy/ioc/specs/OperationTrackerSpec.groovy @@ -0,0 +1,42 @@ +package ioc.specs + +import org.apache.tapestry5.ioc.OperationTracker +import org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl +import org.apache.tapestry5.ioc.internal.LoggerSourceImpl +import org.apache.tapestry5.ioc.internal.OperationException; +import org.apache.tapestry5.ioc.internal.OperationTrackerImpl; +import org.apache.tapestry5.ioc.internal.RegistryImpl +import org.apache.tapestry5.ioc.internal.services.PlasticProxyFactoryImpl +import org.apache.tapestry5.ioc.modules.TapestryIOCModule +import org.apache.tapestry5.ioc.services.OperationTrackedModule +import org.apache.tapestry5.ioc.services.OperationTrackedService +import org.apache.tapestry5.ioc.services.PlasticProxyFactory +import org.slf4j.LoggerFactory; + +import spock.lang.AutoCleanup +import spock.lang.Issue; +import spock.lang.Shared +import spock.lang.Specification + +class OperationTrackerSpec extends Specification { + + + @Issue('TAP5-2486') + def "IOOperation descriptions are reported"() { + setup: + def logger = LoggerFactory.getLogger(OperationTracker) + def operationTracker = new OperationTrackerImpl(logger) + + when: + operationTracker.perform 'Throwing exception', { + throw new IOException() + } + + then: + OperationException ex = thrown() + ex.trace == ['Throwing exception'] + + } + + +}
