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

This commit is contained in:
Lisias 2018-01-08 11:59:24 -02:00
parent d20056380e
commit 86b53fea37
11 changed files with 48 additions and 28 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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());
}
/**

View File

@ -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);

View File

@ -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...)

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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<Integer> 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());
}
}

View File

@ -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$
}
/**