Skip to content

Commit

Permalink
RTTI: Add logging while reading a core file
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Apr 18, 2024
1 parent 86f7377 commit 9b4c7b6
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.shade.platform.model.util.BufferUtils;
import com.shade.util.NotNull;
import com.shade.util.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -23,6 +25,8 @@

public record CoreBinary(@NotNull List<RTTIObject> objects) implements RTTICoreFile {
public record Reader(@NotNull RTTITypeRegistry registry) implements RTTICoreFileReader {
private static final Logger log = LoggerFactory.getLogger(Reader.class);

@NotNull
@Override
public RTTICoreFile read(@NotNull InputStream is, boolean lenient) throws IOException {
Expand Down Expand Up @@ -51,7 +55,7 @@ public RTTICoreFile read(@NotNull InputStream is, boolean lenient) throws IOExce
type = registry.find(hash);

if (type == null) {
continue;
throw new IllegalArgumentException("Can't find type with hash 0x" + Long.toHexString(hash) + " in the registry");
}

final var size = header.getInt(8);
Expand All @@ -61,19 +65,22 @@ public RTTICoreFile read(@NotNull InputStream is, boolean lenient) throws IOExce
throw new IOException("Unexpected end of stream while reading object data");
}
} catch (Exception e) {
if (!lenient) {
if (lenient) {
log.warn("Failed to read object data", e);
continue;
} else {
throw e;
}

continue;
}

RTTIObject object = null;

try {
object = type.read(registry, data);
} catch (Exception e) {
if (!lenient) {
if (lenient) {
log.warn("Failed to construct object of type " + type, e);
} else {
throw e;
}
}
Expand Down

0 comments on commit 9b4c7b6

Please sign in to comment.