From a2468a832f5441e17cdaf5281f171e4b25e6f96e Mon Sep 17 00:00:00 2001 From: Nicholas Novak <34256932+NickyBoy89@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:33:10 -0800 Subject: [PATCH] fix: Returned a file not found error on unity file reads --- storage/unity_file.go | 6 +++++- templates_test.go | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/storage/unity_file.go b/storage/unity_file.go index ab7cb2e..b0da658 100644 --- a/storage/unity_file.go +++ b/storage/unity_file.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "io" + "io/fs" "os" "git.nicholasnovak.io/nnovak/spatial-db/world" @@ -115,7 +116,10 @@ func (u *UnityFile) ReadMetadataFile(fileName string) error { } func (u UnityFile) ReadChunk(pos world.ChunkPos) (world.ChunkData, error) { - m := u.metadata[pos] + m, contains := u.metadata[pos] + if !contains { + return world.ChunkData{}, fs.ErrNotExist + } u.fd.Seek(int64(m.StartOffset), io.SeekStart) diff --git a/templates_test.go b/templates_test.go index 609b6d9..7874651 100644 --- a/templates_test.go +++ b/templates_test.go @@ -2,7 +2,6 @@ package main import ( "errors" - "io" "testing" "git.nicholasnovak.io/nnovak/spatial-db/storage" @@ -19,7 +18,7 @@ func readBlockTemplate( for i := 0; i < b.N; i++ { pos := world.RandomBlockPosWithRange(float64(pointSpread)) if _, err := storageServer.ReadBlockAt(pos); err != nil { - if errors.Is(err, storage.ChunkNotFoundError) || errors.Is(err, io.EOF) { + if errors.Is(err, storage.ChunkNotFoundError) { continue } else { b.Error(err)