Skip to content

Commit cdc736a

Browse files
committed
edited file existence to be more explicit
1 parent 67e1af3 commit cdc736a

File tree

1 file changed

+12
-7
lines changed
  • src/main/java/com/example/core/model

1 file changed

+12
-7
lines changed

src/main/java/com/example/core/model/GGUF.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.example.core.model;
22

33
import com.example.auxiliary.Timer;
4+
import com.example.core.model.GGUF.GGUFTensorInfo;
45
import com.example.core.model.tensor.FloatTensor;
56
import com.example.core.model.tensor.GGMLTensorEntry;
67
import com.example.core.types.MetadataValueType;
78
import com.example.core.types.Pair;
89

10+
import java.io.FileNotFoundException;
911
import java.io.IOException;
1012
import java.lang.foreign.Arena;
1113
import java.lang.foreign.MemorySegment;
1214
import java.nio.ByteBuffer;
1315
import java.nio.ByteOrder;
1416
import java.nio.channels.FileChannel;
1517
import java.nio.charset.StandardCharsets;
18+
import java.nio.file.Files;
1619
import java.nio.file.Path;
1720
import java.util.HashMap;
1821
import java.util.List;
@@ -36,17 +39,19 @@ public final class GGUF {
3639
private long tensorDataOffset;
3740

3841
public static GGUF loadModel(Path modelPath) throws IOException {
42+
43+
// file existence check
44+
if (!Files.exists(modelPath)) {
45+
throw new FileNotFoundException("Model file not found: " + modelPath);
46+
}
47+
48+
// second check to make sure that nothing goes wrong during model loading
3949
try (FileChannel fileChannel = FileChannel.open(modelPath); var ignored = Timer.log("Parse " + modelPath)) {
4050
GGUF gguf = new GGUF();
4151
gguf.loadModelImpl(fileChannel);
4252
return gguf;
43-
} catch {
44-
45-
IOException e -> {
46-
throw new IOException("Failed to load GGUF model from " + modelPath, e);
47-
}
48-
49-
catch (Exception e) {
53+
} catch (Exception e) {
54+
{
5055
throw new RuntimeException("Unexpected error while loading GGUF model from " + modelPath, e);
5156
}
5257

0 commit comments

Comments
 (0)