Skip to content

Commit fd8837c

Browse files
authored
Merge pull request #377 from Wilma456/fserror
Better Errors for fs API
2 parents 2f829a1 + 226ae36 commit fd8837c

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/main/java/dan200/computercraft/core/filesystem/ComboMount.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ else if( foundDirs > 1 )
9494
}
9595
else
9696
{
97-
throw new IOException( "Not a directory" );
97+
throw new IOException( "/" + path + ": Not a directory" );
9898
}
9999
}
100100

@@ -109,7 +109,7 @@ public long getSize( @Nonnull String path ) throws IOException
109109
return part.getSize( path );
110110
}
111111
}
112-
throw new IOException( "No such file" );
112+
throw new IOException( "/" + path + ": No such file" );
113113
}
114114

115115
@Nonnull
@@ -124,6 +124,6 @@ public InputStream openForRead( @Nonnull String path ) throws IOException
124124
return part.openForRead( path );
125125
}
126126
}
127-
throw new IOException( "No such file" );
127+
throw new IOException( "/" + path + ": No such file" );
128128
}
129129
}

src/main/java/dan200/computercraft/core/filesystem/FileMount.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void list( @Nonnull String path, @Nonnull List<String> contents ) throws
129129
{
130130
if( path.length() != 0 )
131131
{
132-
throw new IOException( "Not a directory" );
132+
throw new IOException( "/" + path + ": Not a directory" );
133133
}
134134
}
135135
else
@@ -148,7 +148,7 @@ public void list( @Nonnull String path, @Nonnull List<String> contents ) throws
148148
}
149149
else
150150
{
151-
throw new IOException( "Not a directory" );
151+
throw new IOException( "/" + path + ": Not a directory" );
152152
}
153153
}
154154
}
@@ -178,7 +178,7 @@ public long getSize( @Nonnull String path ) throws IOException
178178
}
179179
}
180180
}
181-
throw new IOException( "No such file" );
181+
throw new IOException( "/" + path + ": No such file" );
182182
}
183183

184184
@Nonnull
@@ -193,7 +193,7 @@ public InputStream openForRead( @Nonnull String path ) throws IOException
193193
return new FileInputStream( file );
194194
}
195195
}
196-
throw new IOException( "No such file" );
196+
throw new IOException( "/" + path + ": No such file" );
197197
}
198198

199199
// IWritableMount implementation
@@ -207,7 +207,7 @@ public void makeDirectory( @Nonnull String path ) throws IOException
207207
{
208208
if( !file.isDirectory() )
209209
{
210-
throw new IOException( "File exists" );
210+
throw new IOException( "/" + path + ": File exists" );
211211
}
212212
}
213213
else
@@ -222,7 +222,7 @@ public void makeDirectory( @Nonnull String path ) throws IOException
222222

223223
if( getRemainingSpace() < dirsToCreate * MINIMUM_FILE_SIZE )
224224
{
225-
throw new IOException( "Out of space" );
225+
throw new IOException( "/" + path + ": Out of space" );
226226
}
227227

228228
boolean success = file.mkdirs();
@@ -232,7 +232,7 @@ public void makeDirectory( @Nonnull String path ) throws IOException
232232
}
233233
else
234234
{
235-
throw new IOException( "Access denied" );
235+
throw new IOException( "/" + path + ": Access denied" );
236236
}
237237
}
238238
}
@@ -242,7 +242,7 @@ public void delete( @Nonnull String path ) throws IOException
242242
{
243243
if( path.length() == 0 )
244244
{
245-
throw new IOException( "Access denied" );
245+
throw new IOException( "/" + path + ": Access denied" );
246246
}
247247

248248
if( created() )
@@ -288,15 +288,15 @@ public OutputStream openForWrite( @Nonnull String path ) throws IOException
288288
File file = getRealPath( path );
289289
if( file.exists() && file.isDirectory() )
290290
{
291-
throw new IOException( "Cannot write to directory" );
291+
throw new IOException( "/" + path + ": Cannot write to directory" );
292292
}
293293
else
294294
{
295295
if( !file.exists() )
296296
{
297297
if( getRemainingSpace() < MINIMUM_FILE_SIZE )
298298
{
299-
throw new IOException( "Out of space" );
299+
throw new IOException( "/" + path + ": Out of space" );
300300
}
301301
else
302302
{
@@ -321,11 +321,11 @@ public OutputStream openForAppend( @Nonnull String path ) throws IOException
321321
File file = getRealPath( path );
322322
if( !file.exists() )
323323
{
324-
throw new IOException( "No such file" );
324+
throw new IOException( "/" + path + ": No such file" );
325325
}
326326
else if( file.isDirectory() )
327327
{
328-
throw new IOException( "Cannot write to directory" );
328+
throw new IOException( "/" + path + ": Cannot write to directory" );
329329
}
330330
else
331331
{
@@ -334,7 +334,7 @@ else if( file.isDirectory() )
334334
}
335335
else
336336
{
337-
throw new IOException( "No such file" );
337+
throw new IOException( "/" + path + ": No such file" );
338338
}
339339
}
340340

src/main/java/dan200/computercraft/core/filesystem/FileSystem.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void list( String path, List<String> contents ) throws FileSystemExceptio
110110
}
111111
else
112112
{
113-
throw new FileSystemException( "Not a directory" );
113+
throw new FileSystemException( "/" + path + ": Not a directory" );
114114
}
115115
}
116116
catch( IOException e )
@@ -137,7 +137,7 @@ public long getSize( String path ) throws FileSystemException
137137
}
138138
else
139139
{
140-
throw new FileSystemException( "No such file" );
140+
throw new FileSystemException( "/" + path + ": No such file" );
141141
}
142142
}
143143
catch( IOException e )
@@ -157,7 +157,7 @@ public InputStream openForRead( String path ) throws FileSystemException
157157
}
158158
else
159159
{
160-
throw new FileSystemException( "No such file" );
160+
throw new FileSystemException( "/" + path + ": No such file" );
161161
}
162162
}
163163
catch( IOException e )
@@ -172,7 +172,7 @@ public void makeDirectory( String path ) throws FileSystemException
172172
{
173173
if( m_writableMount == null )
174174
{
175-
throw new FileSystemException( "Access denied" );
175+
throw new FileSystemException( "/" + path + ": Access denied" );
176176
}
177177
try
178178
{
@@ -181,7 +181,7 @@ public void makeDirectory( String path ) throws FileSystemException
181181
{
182182
if( !m_mount.isDirectory( path ) )
183183
{
184-
throw new FileSystemException( "File exists" );
184+
throw new FileSystemException( "/" + path + ": File exists" );
185185
}
186186
}
187187
else
@@ -199,7 +199,7 @@ public void delete( String path ) throws FileSystemException
199199
{
200200
if( m_writableMount == null )
201201
{
202-
throw new FileSystemException( "Access denied" );
202+
throw new FileSystemException( "/" + path + ": Access denied" );
203203
}
204204
try
205205
{
@@ -219,14 +219,14 @@ public OutputStream openForWrite( String path ) throws FileSystemException
219219
{
220220
if( m_writableMount == null )
221221
{
222-
throw new FileSystemException( "Access denied" );
222+
throw new FileSystemException( "/" + path + ": Access denied" );
223223
}
224224
try
225225
{
226226
path = toLocal( path );
227227
if( m_mount.exists( path ) && m_mount.isDirectory( path ) )
228228
{
229-
throw new FileSystemException( "Cannot write to directory" );
229+
throw new FileSystemException( "/" + path + ": Cannot write to directory" );
230230
}
231231
else
232232
{
@@ -251,7 +251,7 @@ public OutputStream openForAppend( String path ) throws FileSystemException
251251
{
252252
if( m_writableMount == null )
253253
{
254-
throw new FileSystemException( "Access denied" );
254+
throw new FileSystemException( "/" + path + ": Access denied" );
255255
}
256256
try
257257
{
@@ -270,7 +270,7 @@ public OutputStream openForAppend( String path ) throws FileSystemException
270270
}
271271
else if( m_mount.isDirectory( path ) )
272272
{
273-
throw new FileSystemException( "Cannot write to directory" );
273+
throw new FileSystemException( "/" + path + ": Cannot write to directory" );
274274
}
275275
else
276276
{
@@ -557,16 +557,16 @@ public synchronized void copy( String sourcePath, String destPath ) throws FileS
557557
sourcePath = sanitizePath( sourcePath );
558558
destPath = sanitizePath( destPath );
559559
if( isReadOnly( destPath ) ) {
560-
throw new FileSystemException( "Access denied" );
560+
throw new FileSystemException( "/" + destPath + ": Access denied" );
561561
}
562562
if( !exists( sourcePath ) ) {
563-
throw new FileSystemException( "No such file" );
563+
throw new FileSystemException( "/" + sourcePath + ": No such file" );
564564
}
565565
if( exists( destPath ) ) {
566-
throw new FileSystemException( "File exists" );
566+
throw new FileSystemException( "/" + destPath + ": File exists" );
567567
}
568568
if( contains( sourcePath, destPath ) ) {
569-
throw new FileSystemException( "Can't copy a directory inside itself" );
569+
throw new FileSystemException( "/" + sourcePath + ": Can't copy a directory inside itself" );
570570
}
571571
copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) );
572572
}
@@ -730,7 +730,7 @@ private MountWrapper getMount( String path ) throws FileSystemException
730730
}
731731
if( match == null )
732732
{
733-
throw new FileSystemException( "Invalid Path" );
733+
throw new FileSystemException( "/" + path + ": Invalid Path" );
734734
}
735735
return match;
736736
}

src/main/java/dan200/computercraft/core/filesystem/JarMount.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void list( @Nonnull String path, @Nonnull List<String> contents ) throws
203203
}
204204
else
205205
{
206-
throw new IOException( "Not a directory" );
206+
throw new IOException( "/" + path + ": Not a directory" );
207207
}
208208
}
209209

@@ -215,7 +215,7 @@ public long getSize( @Nonnull String path ) throws IOException
215215
{
216216
return file.getSize();
217217
}
218-
throw new IOException( "No such file" );
218+
throw new IOException( "/" + path + ": No such file" );
219219
}
220220

221221
@Nonnull
@@ -243,6 +243,6 @@ public InputStream openForRead( @Nonnull String path ) throws IOException
243243
// treat errors as non-existance of file
244244
}
245245
}
246-
throw new IOException( "No such file" );
246+
throw new IOException( "/" + path + ": No such file" );
247247
}
248248
}

0 commit comments

Comments
 (0)