Skip to content

Commit

Permalink
fix(ZNTA-568): Provide upload failure details to the user
Browse files Browse the repository at this point in the history
Where possible, pass the exception reason to the user so it
is easier to debug a failed upload.
  • Loading branch information
djansen-redhat committed Apr 5, 2018
1 parent cc5ddcd commit 25455a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
Expand Up @@ -96,7 +96,7 @@ public TranslationsResource extractTarget(InputSource inputSource) {

if (message.isHeader()) {
if (headerFound)
throw new IllegalStateException("found a second header!");
throw new IllegalStateException("multiple headers found");
headerFound = true;

// add target header data
Expand Down Expand Up @@ -208,7 +208,7 @@ public Resource extractTemplate(InputSource inputSource,

if (message.isHeader()) {
if (headerFound)
throw new IllegalStateException("found a second header!");
throw new IllegalStateException("multiple headers found");
headerFound = true;

// store POT data
Expand Down
Expand Up @@ -31,6 +31,7 @@
import net.sf.okapi.common.Event;
import net.sf.okapi.common.EventType;
import net.sf.okapi.common.IParameters;
import net.sf.okapi.common.exceptions.OkapiException;
import net.sf.okapi.common.exceptions.OkapiIOException;
import net.sf.okapi.common.filters.IFilter;
import net.sf.okapi.common.filterwriter.GenericContent;
Expand Down Expand Up @@ -197,7 +198,7 @@ public Resource parseDocumentFile(@Nonnull URI documentContent,
}
}
}
} catch (OkapiIOException e) {
} catch (OkapiException e) {
throw new FileFormatAdapterException("Unable to parse document", e);
} finally {
filter.close();
Expand Down Expand Up @@ -332,7 +333,7 @@ protected TranslationsResource parseTranslationFile(RawDocument rawDoc,
}
}
}
} catch (OkapiIOException e) {
} catch (OkapiException e) {
throw new FileFormatAdapterException(
"Unable to parse translation file", e);
} finally {
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.io.Serializable;
import javax.annotation.Nonnull;
import javax.enterprise.context.Dependent;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -282,12 +283,12 @@ private void processAdapterFile(@Nonnull File tempFile, GlobalDocumentId id,
id.getVersionSlug(), doc,
Sets.newHashSet(PotEntryHeader.ID, SimpleComment.ID),
false);
} catch (SecurityException e) {
} catch (SecurityException | ZanataServiceException e) {
throw new DocumentUploadException(Status.INTERNAL_SERVER_ERROR,
e.getMessage(), e);
} catch (ZanataServiceException e) {
} catch (WebApplicationException e) {
throw new DocumentUploadException(Status.INTERNAL_SERVER_ERROR,
e.getMessage(), e);
e.getResponse().getEntity().toString(), e);
}
String contentHash = uploadForm.getHash();
DocumentType documentType =
Expand Down
Expand Up @@ -164,7 +164,7 @@ boolean transferFromTextFlows(List<TextFlow> from, HDocument to,
for (TextFlow tf : from) {
if (!incomingIds.add(tf.getId())) {
Response response = Response.status(Status.BAD_REQUEST).entity(
"encountered TextFlow with duplicate ID " + tf.getId())
"Encountered TextFlow with duplicate ID")
.build();
log.warn(
"encountered TextFlow with duplicate ID {}", tf.getId());
Expand Down
Expand Up @@ -21,6 +21,7 @@
package org.zanata.service.impl;

import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.MapMaker;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -182,11 +183,11 @@ public TranslationsResource parseAdapterTranslationFile(File tempFile,
try {
transRes = adapter.parseTranslationFile(tempFile.toURI(),
doc.getSourceLocaleId(), localeId, getAdapterParams(doc));
} catch (FileFormatAdapterException e) {
throw new ZanataServiceException(
"Error parsing translation file: " + fileName, e);
} catch (RuntimeException e) {
throw new ZanataServiceException(e);
Throwable rootCause = Throwables.getRootCause(e);
throw new ZanataServiceException(
"Translation file error: " + fileName + " " +
rootCause.getMessage(), e);
}
return transRes;
}
Expand Down Expand Up @@ -250,9 +251,12 @@ public Resource parseUpdatedAdapterDocumentFile(URI documentFile,
try {
doc = adapter.parseDocumentFile(documentFile, new LocaleId("en"),
params);
} catch (FileFormatAdapterException e) {
} catch (RuntimeException e) {
Throwable rootCause = Throwables.getRootCause(e);
// Filename may not be a 'file name' e.g GETTEXT
throw new ZanataServiceException(
"Error parsing document file: " + fileName, e);
"Error parsing document file: " + fileName + " " +
rootCause.getMessage(), e);
}
doc.setName(docId);
return doc;
Expand All @@ -268,9 +272,12 @@ private Resource parsePotFile(InputStream fileContents, String docId,
boolean offlinePo) {
PoReader2 poReader = new PoReader2(offlinePo);
// assume english as source locale
Resource res = poReader.extractTemplate(new InputSource(fileContents),
new LocaleId("en"), docId);
return res;
try {
return poReader.extractTemplate(new InputSource(fileContents),
new LocaleId("en"), docId);
} catch (IllegalStateException e) {
throw new ZanataServiceException(e.getMessage());
}
}
// TODO replace these with values from DocumentType

Expand Down

0 comments on commit 25455a2

Please sign in to comment.