Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better exception handling
  • Loading branch information
ajs6f committed Apr 21, 2013
1 parent 6e4f4d3 commit 858fa5e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
@@ -1,6 +1,7 @@

package org.fcrepo.observer;

import static com.google.common.base.Throwables.propagate;
import static org.fcrepo.utils.FedoraTypesUtils.isFedoraDatastream;
import static org.fcrepo.utils.FedoraTypesUtils.isFedoraObject;

Expand All @@ -13,7 +14,6 @@
import javax.jcr.Session;
import javax.jcr.observation.Event;

import org.modeshape.common.SystemFailureException;
import org.modeshape.jcr.api.Repository;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public boolean apply(final Event event) {
// not a node in the fedora workspace
return false;
} catch (final RepositoryException e) {
throw new SystemFailureException(e);
throw propagate(e);
}
}

Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.services;

import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Collections2.transform;
import static com.google.common.collect.ImmutableSet.builder;
import static com.google.common.collect.ImmutableSet.copyOf;
Expand Down Expand Up @@ -164,7 +165,7 @@ public final void getSession() {
try {
readOnlySession = repo.login();
} catch (final RepositoryException e) {
throw new IllegalStateException(e);
throw propagate(e);
}
}

Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.services;

import static com.google.common.base.Throwables.propagate;
import static javax.jcr.query.Query.JCR_SQL2;

import java.io.PrintStream;
Expand Down Expand Up @@ -82,17 +83,15 @@ public Long getRepositorySize(final Session session) {
try {
return getAllObjectsDatastreamSize();
} catch (final RepositoryException e) {
logger.warn(e.toString());
return -1L;
throw propagate(e);
}
}

public Long getRepositoryObjectCount(final Session session) {
try {
return session.getNode("/objects").getNodes().getSize();
} catch (final RepositoryException e) {
logger.warn(e.toString());
return -1L;
throw propagate(e);
}
}

Expand Down Expand Up @@ -121,7 +120,7 @@ public final void getSession() {
try {
readOnlySession = repo.login();
} catch (final RepositoryException e) {
throw new IllegalStateException(e);
throw propagate(e);
}
}

Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.services.functions;

import static com.google.common.base.Throwables.propagate;
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
Expand Down Expand Up @@ -42,7 +43,7 @@ public FixityResult apply(final LowLevelCacheEntry input) {
result = input.checkFixity(dsChecksum, dsSize, digest);
} catch (final BinaryStoreException e) {
logger.error("Exception checking low-level fixity: {}", e);
throw new IllegalStateException(e);
throw propagate(e);
}
return result;
}
Expand Down
Expand Up @@ -2,6 +2,7 @@
package org.fcrepo.services.functions;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.propagate;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

Expand All @@ -22,7 +23,7 @@ public BinaryKey apply(final Node input) {
return ((BinaryValue) input.getNode(JCR_CONTENT).getProperty(
JCR_DATA).getBinary()).getKey();
} catch (final RepositoryException e) {
throw new IllegalArgumentException(e);
throw propagate(e);
}
}

Expand Down
Expand Up @@ -2,6 +2,7 @@
package org.fcrepo.services.functions;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.propagate;

import javax.jcr.Repository;

Expand All @@ -23,7 +24,7 @@ public BinaryStore apply(final Repository input) {
return ((JcrRepository) input).getConfiguration()
.getBinaryStorage().getBinaryStore();
} catch (final Exception e) {
throw new IllegalStateException(e);
throw propagate(e);
}
}

Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.utils;

import static com.google.common.base.Throwables.propagate;
import static org.apache.commons.codec.binary.Hex.encodeHexString;
import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -27,7 +28,7 @@ public static URI asURI(final String algorithm, final String value) {
} catch (final URISyntaxException unlikelyException) {
logger.warn("Exception creating checksum URI: {}",
unlikelyException);
return null;
throw propagate(unlikelyException);
}
}

Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.utils;

import static com.google.common.base.Throwables.propagate;
import static java.util.Objects.hash;
import static org.fcrepo.utils.FixityResult.FixityState.BAD_CHECKSUM;
import static org.fcrepo.utils.FixityResult.FixityState.BAD_SIZE;
Expand Down Expand Up @@ -165,8 +166,9 @@ public FixityResult checkFixity(final URI checksum, final long size,
ds.close();
} catch (final CloneNotSupportedException e) {
logger.warn("Could not clone MessageDigest: {}", e);
throw propagate(e);
} catch (final IOException e) {
throw new IllegalStateException(e);
throw propagate(e);
}

return result;
Expand Down

0 comments on commit 858fa5e

Please sign in to comment.