From 239a2f0d25d698d252f33f6ed4966b49d71dcb8a Mon Sep 17 00:00:00 2001 From: Wilma456 Date: Sat, 15 Jul 2017 16:09:29 +0200 Subject: [PATCH 1/4] Better Errors for fs API --- .../core/filesystem/ComboMount.java | 6 ++-- .../core/filesystem/FileMount.java | 30 +++++++++---------- .../core/filesystem/FileSystem.java | 30 +++++++++---------- .../core/filesystem/JarMount.java | 6 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java index 287ea53a6..b528b6a2d 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java @@ -94,7 +94,7 @@ public class ComboMount implements IMount } else { - throw new IOException( "Not a directory" ); + throw new IOException( "Not a directory (" + path + ")" ); } } @@ -109,7 +109,7 @@ public class ComboMount implements IMount return part.getSize( path ); } } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } @Nonnull @@ -124,6 +124,6 @@ public class ComboMount implements IMount return part.openForRead( path ); } } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index b201ff862..59ce3d826 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -129,7 +129,7 @@ public class FileMount implements IWritableMount { if( path.length() != 0 ) { - throw new IOException( "Not a directory" ); + throw new IOException( "Not a directory (" + path + ")" ); } } else @@ -148,7 +148,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Not a directory" ); + throw new IOException( "Not a directory (" + path + ")" ); } } } @@ -178,7 +178,7 @@ public class FileMount implements IWritableMount } } } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } @Nonnull @@ -193,7 +193,7 @@ public class FileMount implements IWritableMount return new FileInputStream( file ); } } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } // IWritableMount implementation @@ -207,7 +207,7 @@ public class FileMount implements IWritableMount { if( !file.isDirectory() ) { - throw new IOException( "File exists" ); + throw new IOException( "File exists (" + path + ")" ); } } else @@ -222,7 +222,7 @@ public class FileMount implements IWritableMount if( getRemainingSpace() < dirsToCreate * MINIMUM_FILE_SIZE ) { - throw new IOException( "Out of space" ); + throw new IOException( "Out of space (" + path + ")" ); } boolean success = file.mkdirs(); @@ -232,7 +232,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Access denied" ); + throw new IOException( "Access denied (" + path + ")" ); } } } @@ -242,7 +242,7 @@ public class FileMount implements IWritableMount { if( path.length() == 0 ) { - throw new IOException( "Access denied" ); + throw new IOException( "Access denied (" + path + ")" ); } if( created() ) @@ -276,7 +276,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Access denied" ); + throw new IOException( "Access denied (" + path + ")" ); } } @@ -288,7 +288,7 @@ public class FileMount implements IWritableMount File file = getRealPath( path ); if( file.exists() && file.isDirectory() ) { - throw new IOException( "Cannot write to directory" ); + throw new IOException( "Cannot write to directory (" + path + ")" ); } else { @@ -296,7 +296,7 @@ public class FileMount implements IWritableMount { if( getRemainingSpace() < MINIMUM_FILE_SIZE ) { - throw new IOException( "Out of space" ); + throw new IOException( "Out of space (" + path + ")" ); } else { @@ -321,11 +321,11 @@ public class FileMount implements IWritableMount File file = getRealPath( path ); if( !file.exists() ) { - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } else if( file.isDirectory() ) { - throw new IOException( "Cannot write to directory" ); + throw new IOException( "Cannot write to directory (" + path + ")" ); } else { @@ -334,7 +334,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } } @@ -361,7 +361,7 @@ public class FileMount implements IWritableMount boolean success = m_rootPath.mkdirs(); if( !success ) { - throw new IOException( "Access denied" ); + throw new IOException( "Access denied (" + path + ")" ); } } } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index cab9abdac..662d14842 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -110,7 +110,7 @@ public class FileSystem } else { - throw new FileSystemException( "Not a directory" ); + throw new FileSystemException( "Not a directory (" + path + ")" ); } } catch( IOException e ) @@ -137,7 +137,7 @@ public class FileSystem } else { - throw new FileSystemException( "No such file" ); + throw new FileSystemException( "No such file (" + path + ")" ); } } catch( IOException e ) @@ -157,7 +157,7 @@ public class FileSystem } else { - throw new FileSystemException( "No such file" ); + throw new FileSystemException( "No such file (" + path + ")" ); } } catch( IOException e ) @@ -172,7 +172,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied" ); + throw new FileSystemException( "Access denied (" + path + ")" ); } try { @@ -181,7 +181,7 @@ public class FileSystem { if( !m_mount.isDirectory( path ) ) { - throw new FileSystemException( "File exists" ); + throw new FileSystemException( "File exists (" + path + ")" ); } } else @@ -199,7 +199,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied" ); + throw new FileSystemException( "Access denied (" + path + ")" ); } try { @@ -219,14 +219,14 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied" ); + throw new FileSystemException( "Access denied (" + path + ")" ); } try { path = toLocal( path ); if( m_mount.exists( path ) && m_mount.isDirectory( path ) ) { - throw new FileSystemException( "Cannot write to directory" ); + throw new FileSystemException( "Cannot write to directory (" + path + ")" ); } else { @@ -251,7 +251,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied" ); + throw new FileSystemException( "Access denied (" + path + ")" ); } try { @@ -270,7 +270,7 @@ public class FileSystem } else if( m_mount.isDirectory( path ) ) { - throw new FileSystemException( "Cannot write to directory" ); + throw new FileSystemException( "Cannot write to directory (" + path + ")" ); } else { @@ -557,16 +557,16 @@ public class FileSystem sourcePath = sanitizePath( sourcePath ); destPath = sanitizePath( destPath ); if( isReadOnly( destPath ) ) { - throw new FileSystemException( "Access denied" ); + throw new FileSystemException( "Access denied (" + destPath + ")" ); } if( !exists( sourcePath ) ) { - throw new FileSystemException( "No such file" ); + throw new FileSystemException( "No such file (" + sourcePath + ")" ); } if( exists( destPath ) ) { - throw new FileSystemException( "File exists" ); + throw new FileSystemException( "File exists (" + destPath + ")" ); } if( contains( sourcePath, destPath ) ) { - throw new FileSystemException( "Can't copy a directory inside itself" ); + throw new FileSystemException( "Can't copy a directory inside itself (" + sourcePath + ")" ); } copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) ); } @@ -730,7 +730,7 @@ public class FileSystem } if( match == null ) { - throw new FileSystemException( "Invalid Path" ); + throw new FileSystemException( "Invalid Path (" + path + ")" ); } return match; } diff --git a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java index 3bc4988e7..f63457b88 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java @@ -203,7 +203,7 @@ public class JarMount implements IMount } else { - throw new IOException( "Not a directory" ); + throw new IOException( "Not a directory (" + path + ")" ); } } @@ -215,7 +215,7 @@ public class JarMount implements IMount { return file.getSize(); } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } @Nonnull @@ -243,6 +243,6 @@ public class JarMount implements IMount // treat errors as non-existance of file } } - throw new IOException( "No such file" ); + throw new IOException( "No such file (" + path + ")" ); } } From f28a1ba517fc0e3cca311c837546f5c69c862ae0 Mon Sep 17 00:00:00 2001 From: Wilma456 Date: Sat, 15 Jul 2017 16:41:40 +0200 Subject: [PATCH 2/4] Fix Bugs --- .../java/dan200/computercraft/core/filesystem/FileMount.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index 59ce3d826..d81fd8fcf 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -276,7 +276,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Access denied (" + path + ")" ); + throw new IOException( "Access denied" ); } } @@ -361,7 +361,7 @@ public class FileMount implements IWritableMount boolean success = m_rootPath.mkdirs(); if( !success ) { - throw new IOException( "Access denied (" + path + ")" ); + throw new IOException( "Access denied" ); } } } From 0a5155c0ffc7af9feb2b336e9887b2270fe393d2 Mon Sep 17 00:00:00 2001 From: Wilma456 Date: Thu, 27 Jul 2017 16:40:00 +0200 Subject: [PATCH 3/4] New style --- .../core/filesystem/ComboMount.java | 6 ++-- .../core/filesystem/FileMount.java | 26 ++++++++--------- .../core/filesystem/FileSystem.java | 28 +++++++++---------- .../core/filesystem/JarMount.java | 6 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java index b528b6a2d..71222f5f6 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java @@ -94,7 +94,7 @@ public class ComboMount implements IMount } else { - throw new IOException( "Not a directory (" + path + ")" ); + throw new IOException( "/" + path + ": Not a directory" ); } } @@ -109,7 +109,7 @@ public class ComboMount implements IMount return part.getSize( path ); } } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } @Nonnull @@ -124,6 +124,6 @@ public class ComboMount implements IMount return part.openForRead( path ); } } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index d81fd8fcf..968a2232d 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -129,7 +129,7 @@ public class FileMount implements IWritableMount { if( path.length() != 0 ) { - throw new IOException( "Not a directory (" + path + ")" ); + throw new IOException( "/" + path + ": Not a directory" ); } } else @@ -148,7 +148,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Not a directory (" + path + ")" ); + throw new IOException( "/" + path + ": Not a directory" ); } } } @@ -178,7 +178,7 @@ public class FileMount implements IWritableMount } } } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } @Nonnull @@ -193,7 +193,7 @@ public class FileMount implements IWritableMount return new FileInputStream( file ); } } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } // IWritableMount implementation @@ -207,7 +207,7 @@ public class FileMount implements IWritableMount { if( !file.isDirectory() ) { - throw new IOException( "File exists (" + path + ")" ); + throw new IOException( "/" + path + ": File exists" ); } } else @@ -222,7 +222,7 @@ public class FileMount implements IWritableMount if( getRemainingSpace() < dirsToCreate * MINIMUM_FILE_SIZE ) { - throw new IOException( "Out of space (" + path + ")" ); + throw new IOException( "/" + path + ": Out of space" ); } boolean success = file.mkdirs(); @@ -232,7 +232,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "Access denied (" + path + ")" ); + throw new IOException( "/" + path + ": Access denied" ); } } } @@ -242,7 +242,7 @@ public class FileMount implements IWritableMount { if( path.length() == 0 ) { - throw new IOException( "Access denied (" + path + ")" ); + throw new IOException( "/" + path + ": Access denied" ); } if( created() ) @@ -288,7 +288,7 @@ public class FileMount implements IWritableMount File file = getRealPath( path ); if( file.exists() && file.isDirectory() ) { - throw new IOException( "Cannot write to directory (" + path + ")" ); + throw new IOException( "/" + path + ": Cannot write to directory" ); } else { @@ -296,7 +296,7 @@ public class FileMount implements IWritableMount { if( getRemainingSpace() < MINIMUM_FILE_SIZE ) { - throw new IOException( "Out of space (" + path + ")" ); + throw new IOException( "/" + path + ": Out of space" ); } else { @@ -321,11 +321,11 @@ public class FileMount implements IWritableMount File file = getRealPath( path ); if( !file.exists() ) { - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } else if( file.isDirectory() ) { - throw new IOException( "Cannot write to directory (" + path + ")" ); + throw new IOException( "/" + path + ": Cannot write to directory" ); } else { @@ -334,7 +334,7 @@ public class FileMount implements IWritableMount } else { - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 662d14842..00a4d1ca6 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -110,7 +110,7 @@ public class FileSystem } else { - throw new FileSystemException( "Not a directory (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Not a directory" ); } } catch( IOException e ) @@ -137,7 +137,7 @@ public class FileSystem } else { - throw new FileSystemException( "No such file (" + path + ")" ); + throw new FileSystemException( "/" + path + ": No such file" ); } } catch( IOException e ) @@ -157,7 +157,7 @@ public class FileSystem } else { - throw new FileSystemException( "No such file (" + path + ")" ); + throw new FileSystemException( "/" + path + ": No such file" ); } } catch( IOException e ) @@ -172,7 +172,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Access denied" ); } try { @@ -181,7 +181,7 @@ public class FileSystem { if( !m_mount.isDirectory( path ) ) { - throw new FileSystemException( "File exists (" + path + ")" ); + throw new FileSystemException( "/" + path + ": File exists" ); } } else @@ -199,7 +199,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Access denied" ); } try { @@ -219,14 +219,14 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Access denied" ); } try { path = toLocal( path ); if( m_mount.exists( path ) && m_mount.isDirectory( path ) ) { - throw new FileSystemException( "Cannot write to directory (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Cannot write to directory" ); } else { @@ -251,7 +251,7 @@ public class FileSystem { if( m_writableMount == null ) { - throw new FileSystemException( "Access denied (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Access denied" ); } try { @@ -270,7 +270,7 @@ public class FileSystem } else if( m_mount.isDirectory( path ) ) { - throw new FileSystemException( "Cannot write to directory (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Cannot write to directory" ); } else { @@ -557,16 +557,16 @@ public class FileSystem sourcePath = sanitizePath( sourcePath ); destPath = sanitizePath( destPath ); if( isReadOnly( destPath ) ) { - throw new FileSystemException( "Access denied (" + destPath + ")" ); + throw new FileSystemException( "/" + destPath + ": Access denied" ); } if( !exists( sourcePath ) ) { - throw new FileSystemException( "No such file (" + sourcePath + ")" ); + throw new FileSystemException( "/" + sourcePath + ": No such file" ); } if( exists( destPath ) ) { - throw new FileSystemException( "File exists (" + destPath + ")" ); + throw new FileSystemException( "/" + destPath + ": File exists" ); } if( contains( sourcePath, destPath ) ) { - throw new FileSystemException( "Can't copy a directory inside itself (" + sourcePath + ")" ); + throw new FileSystemException( "/" + sourcePath + ": Can't copy a directory inside itself" ); } copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) ); } diff --git a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java index f63457b88..3dc7b2b27 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java @@ -203,7 +203,7 @@ public class JarMount implements IMount } else { - throw new IOException( "Not a directory (" + path + ")" ); + throw new IOException( "/" + path + ": Not a directory" ); } } @@ -215,7 +215,7 @@ public class JarMount implements IMount { return file.getSize(); } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } @Nonnull @@ -243,6 +243,6 @@ public class JarMount implements IMount // treat errors as non-existance of file } } - throw new IOException( "No such file (" + path + ")" ); + throw new IOException( "/" + path + ": No such file" ); } } From 226ae3648f3c8df55bc9df472263bff43ae24767 Mon Sep 17 00:00:00 2001 From: Wilma456 Date: Fri, 28 Jul 2017 15:21:15 +0200 Subject: [PATCH 4/4] Forget string --- .../java/dan200/computercraft/core/filesystem/FileSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 00a4d1ca6..a1bf00e30 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -730,7 +730,7 @@ public class FileSystem } if( match == null ) { - throw new FileSystemException( "Invalid Path (" + path + ")" ); + throw new FileSystemException( "/" + path + ": Invalid Path" ); } return match; }