mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 22:29:24 +00:00
exception
This commit is contained in:
parent
a95743286e
commit
a6e70b3df1
@ -411,7 +411,7 @@ public class CustomPDFDocumentFactory {
|
|||||||
try {
|
try {
|
||||||
document.setAllSecurityToBeRemoved(true);
|
document.setAllSecurityToBeRemoved(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Decryption failed", e);
|
ExceptionUtils.logException("PDF decryption", e);
|
||||||
throw new IOException("PDF decryption failed", e);
|
throw new IOException("PDF decryption failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public class MergeController {
|
|||||||
try (PDDocument doc = pdfDocumentFactory.load(file)) {
|
try (PDDocument doc = pdfDocumentFactory.load(file)) {
|
||||||
pageIndex += doc.getNumberOfPages();
|
pageIndex += doc.getNumberOfPages();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error loading document for TOC generation", e);
|
ExceptionUtils.logException("document loading for TOC generation", e);
|
||||||
pageIndex++; // Increment by at least one if we can't determine page count
|
pageIndex++; // Increment by at least one if we can't determine page count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,7 +240,11 @@ public class MergeController {
|
|||||||
baos, mergedFileName); // Return the modified PDF
|
baos, mergedFileName); // Return the modified PDF
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Error in merge pdf process", ex);
|
if (ex instanceof IOException && PdfErrorUtils.isCorruptedPdfError((IOException) ex)) {
|
||||||
|
log.warn("Corrupted PDF detected in merge pdf process: {}", ex.getMessage());
|
||||||
|
} else {
|
||||||
|
log.error("Error in merge pdf process", ex);
|
||||||
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (mergedDocument != null) {
|
if (mergedDocument != null) {
|
||||||
|
@ -25,6 +25,7 @@ import stirling.software.SPDF.model.SortTypes;
|
|||||||
import stirling.software.SPDF.model.api.PDFWithPageNums;
|
import stirling.software.SPDF.model.api.PDFWithPageNums;
|
||||||
import stirling.software.SPDF.model.api.general.RearrangePagesRequest;
|
import stirling.software.SPDF.model.api.general.RearrangePagesRequest;
|
||||||
import stirling.software.common.service.CustomPDFDocumentFactory;
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
|
import stirling.software.common.util.ExceptionUtils;
|
||||||
import stirling.software.common.util.GeneralUtils;
|
import stirling.software.common.util.GeneralUtils;
|
||||||
import stirling.software.common.util.WebResponseUtils;
|
import stirling.software.common.util.WebResponseUtils;
|
||||||
|
|
||||||
@ -288,7 +289,7 @@ public class RearrangePagesPDFController {
|
|||||||
.replaceFirst("[.][^.]+$", "")
|
.replaceFirst("[.][^.]+$", "")
|
||||||
+ "_rearranged.pdf");
|
+ "_rearranged.pdf");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed rearranging documents", e);
|
ExceptionUtils.logException("document rearrangement", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import stirling.software.SPDF.model.api.PDFWithPageNums;
|
import stirling.software.SPDF.model.api.PDFWithPageNums;
|
||||||
import stirling.software.common.service.CustomPDFDocumentFactory;
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
|
import stirling.software.common.util.ExceptionUtils;
|
||||||
import stirling.software.common.util.WebResponseUtils;
|
import stirling.software.common.util.WebResponseUtils;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -96,7 +97,7 @@ public class SplitPDFController {
|
|||||||
|
|
||||||
splitDocumentsBoas.add(baos);
|
splitDocumentsBoas.add(baos);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed splitting documents and saving them", e);
|
ExceptionUtils.logException("document splitting and saving", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ public class SplitPdfByChaptersController {
|
|||||||
Bookmark lastBookmark = bookmarks.get(bookmarks.size() - 1);
|
Bookmark lastBookmark = bookmarks.get(bookmarks.size() - 1);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unable to extract outline items", e);
|
ExceptionUtils.logException("outline extraction", e);
|
||||||
return ResponseEntity.internalServerError()
|
return ResponseEntity.internalServerError()
|
||||||
.body("Unable to extract outline items".getBytes());
|
.body("Unable to extract outline items".getBytes());
|
||||||
}
|
}
|
||||||
@ -294,7 +294,7 @@ public class SplitPdfByChaptersController {
|
|||||||
|
|
||||||
splitDocumentsBoas.add(baos);
|
splitDocumentsBoas.add(baos);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed splitting documents and saving them", e);
|
ExceptionUtils.logException("document splitting and saving", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public class SplitPdfBySizeController {
|
|||||||
|
|
||||||
log.debug("PDF splitting completed successfully");
|
log.debug("PDF splitting completed successfully");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error loading or processing PDF document", e);
|
ExceptionUtils.logException("PDF document loading or processing", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -114,7 +114,7 @@ public class SplitPdfBySizeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception during PDF splitting process", e);
|
ExceptionUtils.logException("PDF splitting process", e);
|
||||||
throw e; // Re-throw to ensure proper error response
|
throw e; // Re-throw to ensure proper error response
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@ -278,7 +278,7 @@ public class SplitPdfBySizeController {
|
|||||||
currentDoc = pdfDocumentFactory.createNewDocumentBasedOnOldDocument(sourceDocument);
|
currentDoc = pdfDocumentFactory.createNewDocumentBasedOnOldDocument(sourceDocument);
|
||||||
log.debug("Successfully created initial output document");
|
log.debug("Successfully created initial output document");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error creating initial output document", e);
|
ExceptionUtils.logException("initial output document creation", e);
|
||||||
throw ExceptionUtils.createFileProcessingException("split", e);
|
throw ExceptionUtils.createFileProcessingException("split", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,7 +606,7 @@ public class CompressController {
|
|||||||
return "empty-stream";
|
return "empty-stream";
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error generating image hash", e);
|
ExceptionUtils.logException("image hash generation", e);
|
||||||
return "fallback-" + System.identityHashCode(image);
|
return "fallback-" + System.identityHashCode(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import stirling.software.common.model.api.PDFFile;
|
import stirling.software.common.model.api.PDFFile;
|
||||||
import stirling.software.common.service.CustomPDFDocumentFactory;
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
|
import stirling.software.common.util.ExceptionUtils;
|
||||||
import stirling.software.common.util.WebResponseUtils;
|
import stirling.software.common.util.WebResponseUtils;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -134,7 +135,7 @@ public class DecompressPdfController {
|
|||||||
stream.setInt(COSName.LENGTH, decompressedBytes.length);
|
stream.setInt(COSName.LENGTH, decompressedBytes.length);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error decompressing stream", e);
|
ExceptionUtils.logException("stream decompression", e);
|
||||||
// Continue processing other streams even if this one fails
|
// Continue processing other streams even if this one fails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,10 +113,7 @@ public class ExtractImagesController {
|
|||||||
allowDuplicates);
|
allowDuplicates);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Log the error and continue processing other pages
|
// Log the error and continue processing other pages
|
||||||
log.error(
|
ExceptionUtils.logException("image extraction from page " + pageNum, e);
|
||||||
"Error extracting images from page {}: {}",
|
|
||||||
pageNum,
|
|
||||||
e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null; // Callable requires a return type
|
return null; // Callable requires a return type
|
||||||
|
@ -150,11 +150,18 @@ public class PipelineProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasInputFileType) {
|
if (!hasInputFileType) {
|
||||||
|
String filename = file.getFilename();
|
||||||
|
String providedExtension = "no extension";
|
||||||
|
if (filename != null && filename.contains(".")) {
|
||||||
|
providedExtension = filename.substring(filename.lastIndexOf(".")).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
logPrintStream.println(
|
logPrintStream.println(
|
||||||
"No files with extension "
|
"No files with extension "
|
||||||
+ String.join(", ", inputFileTypes)
|
+ String.join(", ", inputFileTypes)
|
||||||
+ " found for operation "
|
+ " found for operation "
|
||||||
+ operation);
|
+ operation
|
||||||
|
+ ". Provided file '" + filename + "' has extension: " + providedExtension);
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,11 +210,26 @@ public class PipelineProcessor {
|
|||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Get details about what files were actually provided
|
||||||
|
List<String> providedExtensions = outputFiles.stream()
|
||||||
|
.map(file -> {
|
||||||
|
String filename = file.getFilename();
|
||||||
|
if (filename != null && filename.contains(".")) {
|
||||||
|
return filename.substring(filename.lastIndexOf(".")).toLowerCase();
|
||||||
|
}
|
||||||
|
return "no extension";
|
||||||
|
})
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
|
||||||
logPrintStream.println(
|
logPrintStream.println(
|
||||||
"No files with extension "
|
"No files with extension "
|
||||||
+ String.join(", ", inputFileTypes)
|
+ String.join(", ", inputFileTypes)
|
||||||
+ " found for multi-input operation "
|
+ " found for multi-input operation "
|
||||||
+ operation);
|
+ operation
|
||||||
|
+ ". Provided files have extensions: "
|
||||||
|
+ String.join(", ", providedExtensions)
|
||||||
|
+ " (total files: " + outputFiles.size() + ")");
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class CertSignController {
|
|||||||
}
|
}
|
||||||
doc.saveIncremental(output);
|
doc.saveIncremental(output);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("exception", e);
|
ExceptionUtils.logException("PDF signing", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import stirling.software.common.model.api.PDFFile;
|
import stirling.software.common.model.api.PDFFile;
|
||||||
import stirling.software.common.service.CustomPDFDocumentFactory;
|
import stirling.software.common.service.CustomPDFDocumentFactory;
|
||||||
|
import stirling.software.common.util.ExceptionUtils;
|
||||||
import stirling.software.common.util.WebResponseUtils;
|
import stirling.software.common.util.WebResponseUtils;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -181,7 +182,7 @@ public class GetInfoOnPDF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("exception", e);
|
ExceptionUtils.logException("PDF standard checking", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -77,7 +77,7 @@ public class MetricsAggregatorService {
|
|||||||
double lastCount = lastSentMetrics.getOrDefault(key, 0.0);
|
double lastCount = lastSentMetrics.getOrDefault(key, 0.0);
|
||||||
double difference = currentCount - lastCount;
|
double difference = currentCount - lastCount;
|
||||||
if (difference > 0) {
|
if (difference > 0) {
|
||||||
logger.info("{}, {}", key, difference);
|
logger.debug("{}, {}", key, difference);
|
||||||
metrics.put(key, difference);
|
metrics.put(key, difference);
|
||||||
lastSentMetrics.put(key, currentCount);
|
lastSentMetrics.put(key, currentCount);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user