From 86b53fea379d88efd128d6a1e35f8d6c07967d25 Mon Sep 17 00:00:00 2001 From: Lisias Date: Mon, 8 Jan 2018 11:59:24 -0200 Subject: [PATCH] Adding the image fullpathname to all DiskExceptions. This will normalize the User Warnings, as also will make easier to feed error reports to an eventual First Aid tool --- .../storage/DiskCorruptException.java | 12 +++++----- .../applecommander/storage/DiskException.java | 5 +++- .../storage/DiskFullException.java | 4 ++-- .../storage/os/cpm/CpmFormatDisk.java | 4 +++- .../storage/os/dos33/DosFormatDisk.java | 9 +++++--- .../os/gutenberg/GutenbergFormatDisk.java | 7 ++++-- .../storage/os/pascal/PascalFileEntry.java | 2 +- .../storage/os/pascal/PascalFormatDisk.java | 4 +++- .../ProdosDiskSizeDoesNotMatchException.java | 4 ++-- .../storage/os/prodos/ProdosFormatDisk.java | 23 ++++++++++++------- .../storage/os/rdos/RdosFormatDisk.java | 2 +- 11 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java index 29f7ac4..fbcdf70 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskCorruptException.java @@ -38,11 +38,11 @@ public class DiskCorruptException extends DiskException { } } - final public Kind kind; - final public Object offender; + public final Kind kind; + public final Object offender; - private DiskCorruptException(final String description) { - super(description); + private DiskCorruptException(final String description, final String imagepath) { + super(description, imagepath); this.kind = null; this.offender = null; } @@ -50,8 +50,8 @@ public class DiskCorruptException extends DiskException { /** * Constructor for DiskFullException. */ - public DiskCorruptException(final Kind kind, final Object offender) { - super(kind.toString()); + public DiskCorruptException(final String imagepath, final Kind kind, final Object offender) { + super(kind.toString(), imagepath); this.kind = kind; this.offender = offender; } diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java index 1cb4ef3..3ef821a 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DiskException.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java @@ -29,10 +29,13 @@ public abstract class DiskException extends Exception { private static final long serialVersionUID = 0xFFFFFFFF80000000L; + public final String imagepath; + /** * Constructor for DiskException. */ - public DiskException(String description) { + public DiskException(final String description, final String imagepath) { super(description); + this.imagepath = imagepath; } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java index de28f56..40e22da 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java @@ -36,7 +36,7 @@ public class DiskFullException extends DiskException { /** * Constructor for DiskFullException. */ - public DiskFullException(String description) { - super(description); + public DiskFullException(final String description, final String imagepath) { + super(description, imagepath); } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/cpm/CpmFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/cpm/CpmFormatDisk.java index 6c3ff83..ac58216 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/cpm/CpmFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/cpm/CpmFormatDisk.java @@ -407,7 +407,9 @@ public class CpmFormatDisk extends FormattedDisk { * @see com.webcodepro.applecommander.storage.DirectoryEntry#createFile() */ public FileEntry createFile() throws DiskFullException { - throw new DiskFullException(textBundle.get("FileCreationNotSupported")); //$NON-NLS-1$ + throw new DiskFullException( + textBundle.get("FileCreationNotSupported") //$NON-NLS-1$ + , this.getFilename()); } /** diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/dos33/DosFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/dos33/DosFormatDisk.java index 320b04c..5448a33 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/dos33/DosFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/dos33/DosFormatDisk.java @@ -152,7 +152,7 @@ public class DosFormatDisk extends FormattedDisk { // Prevents a recursive catalog crawling. final DosSectorAddress address = new DosSectorAddress(track, sector); - if ( visits.contains(address)) throw new DiskCorruptException(DiskCorruptException.Kind.RECURSIVE_DIRECTORY_STRUCTURE, address); + if ( visits.contains(address)) throw new DiskCorruptException(this.getFilename(), DiskCorruptException.Kind.RECURSIVE_DIRECTORY_STRUCTURE, address); else visits.add(address); byte[] catalogSector = readSector(track, sector); @@ -189,7 +189,9 @@ public class DosFormatDisk extends FormattedDisk { track = catalogSector[1]; sector = catalogSector[2]; } - throw new DiskFullException(textBundle.get("DosFormatDisk.NoMoreSpaceError")); //$NON-NLS-1$ + throw new DiskFullException( + textBundle.get("DosFormatDisk.NoMoreSpaceError") //$NON-NLS-1$ + , this.getFilename()); } /** @@ -472,7 +474,8 @@ public class DosFormatDisk extends FormattedDisk { if (numberOfSectors > getFreeSectors() + fileEntry.getSectorsUsed()) { throw new DiskFullException( textBundle.format("DosFormatDisk.NotEnoughSectorsError", //$NON-NLS-1$ - numberOfSectors, getFreeSectors())); + numberOfSectors, getFreeSectors()) + , this.getFilename()); } // free "old" data and just rewrite stuff... freeSectors(fileEntry); diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/gutenberg/GutenbergFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/gutenberg/GutenbergFormatDisk.java index aa1459c..2cb8cbb 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/gutenberg/GutenbergFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/gutenberg/GutenbergFormatDisk.java @@ -172,7 +172,9 @@ public class GutenbergFormatDisk extends FormattedDisk { track = catalogSector[1]; sector = catalogSector[2]; } - throw new DiskFullException(textBundle.get("DosFormatDisk.NoMoreSpaceError")); //$NON-NLS-1$ + throw new DiskFullException( + textBundle.get("DosFormatDisk.NoMoreSpaceError") //$NON-NLS-1$ + , this.getFilename()); } /** @@ -436,7 +438,8 @@ public class GutenbergFormatDisk extends FormattedDisk { if (numberOfSectors > getFreeSectors() + fileEntry.getSectorsUsed()) { throw new DiskFullException( textBundle.format("DosFormatDisk.NotEnoughSectorsError", //$NON-NLS-1$ - numberOfSectors, getFreeSectors())); + numberOfSectors, getFreeSectors()) + , this.getFilename()); } // free "old" data and just rewrite stuff... // freeSectors(fileEntry); (not going to work...) diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFileEntry.java b/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFileEntry.java index 2de1ea2..a978e80 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFileEntry.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFileEntry.java @@ -351,7 +351,7 @@ public class PascalFileEntry implements FileEntry { volEntry.setFileCount(count - 2); dir.set(0, volEntry); disk.putDirectory(dir); - throw new DiskFullException(s); + throw new DiskFullException(s, this.disk.getFilename()); } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java index 3a6d135..82fab46 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java @@ -233,7 +233,9 @@ public class PascalFormatDisk extends FormattedDisk { putDirectory(dir); return entry; } else { - throw new DiskFullException(textBundle.get("PascalFormatDisk.DiskFull")); //$NON-NLS-1$ + throw new DiskFullException( + textBundle.get("PascalFormatDisk.DiskFull") //$NON-NLS-1$ + , this.getFilename()); } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDiskSizeDoesNotMatchException.java b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDiskSizeDoesNotMatchException.java index c7eb317..b501ad8 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDiskSizeDoesNotMatchException.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosDiskSizeDoesNotMatchException.java @@ -37,7 +37,7 @@ public class ProdosDiskSizeDoesNotMatchException extends DiskFullException { /** * Constructor for ProdosDiskSizeDoesNotMatchException. */ - public ProdosDiskSizeDoesNotMatchException(String description) { - super(description); + public ProdosDiskSizeDoesNotMatchException(String description, final String imagepath) { + super(description, imagepath); } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java index 0f25555..973882a 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFormatDisk.java @@ -257,7 +257,7 @@ public class ProdosFormatDisk extends FormattedDisk { } blockNumber = nextBlockNumber; } - throw new DiskFullException(textBundle.get("ProdosFormatDisk.UnableToAllocateSpaceError")); //$NON-NLS-1$ + throw new DiskFullException(textBundle.get("ProdosFormatDisk.UnableToAllocateSpaceError"), this.getFilename()); //$NON-NLS-1$ } /** @@ -278,7 +278,7 @@ public class ProdosFormatDisk extends FormattedDisk { final Set visits = new HashSet<>(); while (blockNumber != 0) { // Prevents a recursive catalog crawling. - if ( visits.contains(blockNumber)) throw new DiskCorruptException(DiskCorruptException.Kind.RECURSIVE_DIRECTORY_STRUCTURE, new ProdosBlockAddress(blockNumber)); + if ( visits.contains(blockNumber)) throw new DiskCorruptException(this.getFilename(), DiskCorruptException.Kind.RECURSIVE_DIRECTORY_STRUCTURE, new ProdosBlockAddress(blockNumber)); else visits.add(blockNumber); byte[] block = readBlock(blockNumber); @@ -656,7 +656,8 @@ public class ProdosFormatDisk extends FormattedDisk { if (numberOfBlocks > getFreeBlocks() + fileEntry.getBlocksUsed()) { throw new DiskFullException(textBundle. format("ProdosFormatDisk.NotEnoughSpaceOnDiskError", //$NON-NLS-1$ - numberOfBlocks, getFreeBlocks())); + numberOfBlocks, getFreeBlocks()) + , this.getFilename()); } // free "old" data and just rewrite stuff... freeBlocks(fileEntry); @@ -761,7 +762,8 @@ public class ProdosFormatDisk extends FormattedDisk { if (numberOfBlocks > getFreeBlocks() + fileEntry.getBlocksUsed()) { throw new DiskFullException(textBundle. format("ProdosFormatDisk.NotEnoughSpaceOnDiskError", //$NON-NLS-1$ - numberOfBlocks, getFreeBlocks())); + numberOfBlocks, getFreeBlocks()) + , this.getFilename()); } // free "old" data and just rewrite stuff... freeBlocks(fileEntry); @@ -928,7 +930,8 @@ public class ProdosFormatDisk extends FormattedDisk { if (numberOfBlocks > getFreeBlocks() + fileEntry.getBlocksUsed()) { throw new DiskFullException(textBundle. format("ProdosFormatDisk.NotEnoughSpaceOnDiskError", //$NON-NLS-1$ - numberOfBlocks, getFreeBlocks())); + numberOfBlocks, getFreeBlocks()) + , this.getFilename()); } // free "old" data and just rewrite stuff... freeBlocks(fileEntry); @@ -1069,12 +1072,14 @@ public class ProdosFormatDisk extends FormattedDisk { return block; } throw new ProdosDiskSizeDoesNotMatchException( - textBundle.get("ProdosFormatDisk.ProdosDiskSizeDoesNotMatchError")); //$NON-NLS-1$ + textBundle.get("ProdosFormatDisk.ProdosDiskSizeDoesNotMatchError") //$NON-NLS-1$ + , this.getFilename()); } block++; } throw new DiskFullException( - textBundle.get("ProdosFormatDisk.NoFreeBlockAvailableError")); //$NON-NLS-1$ + textBundle.get("ProdosFormatDisk.NoFreeBlockAvailableError") //$NON-NLS-1$ + , this.getFilename()); } /** @@ -1423,6 +1428,8 @@ public class ProdosFormatDisk extends FormattedDisk { } blockNumber = nextBlockNumber; } - throw new DiskFullException(textBundle.get("ProdosFormatDisk.UnableToAllocateSpaceError")); //$NON-NLS-1$ + throw new DiskFullException( + textBundle.get("ProdosFormatDisk.UnableToAllocateSpaceError") //$NON-NLS-1$ + , this.getFilename()); } } diff --git a/src/main/java/com/webcodepro/applecommander/storage/os/rdos/RdosFormatDisk.java b/src/main/java/com/webcodepro/applecommander/storage/os/rdos/RdosFormatDisk.java index 408eaef..ef1eeb4 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/os/rdos/RdosFormatDisk.java +++ b/src/main/java/com/webcodepro/applecommander/storage/os/rdos/RdosFormatDisk.java @@ -202,7 +202,7 @@ public class RdosFormatDisk extends FormattedDisk { * Create a new FileEntry. */ public FileEntry createFile() throws DiskFullException { - throw new DiskFullException(textBundle.get("FileCreationNotSupported")); //$NON-NLS-1$ + throw new DiskFullException(textBundle.get("FileCreationNotSupported"), this.getFilename()); //$NON-NLS-1$ } /**