Skip to content

Commit 5de7d75

Browse files
committed
šŸ› fix(PathSerializer): handle InvalidPathException during path deserialization
- add try-catch block to catch InvalidPathException - throw SerializationException with detailed message on failure
1 parent 48c45d7 commit 5de7d75

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/serializer

ā€Žsurf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/config/serializer/PathSerializer.ktā€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package dev.slne.surf.api.core.config.serializer
22

33
import org.spongepowered.configurate.serialize.ScalarSerializer
4+
import org.spongepowered.configurate.serialize.SerializationException
45
import java.lang.reflect.AnnotatedType
6+
import java.nio.file.InvalidPathException
57
import java.nio.file.Path
68
import java.util.function.Predicate
79

810
internal object PathSerializer : ScalarSerializer.Annotated<Path>(Path::class.java) {
911
override fun deserialize(type: AnnotatedType, obj: Any): Path {
10-
return Path.of(obj.toString())
12+
try {
13+
return Path.of(obj.toString())
14+
} catch (e: InvalidPathException) {
15+
throw SerializationException(Path::class.java, "$obj($type) is not a valid path", e)
16+
}
1117
}
1218

1319
override fun serialize(type: AnnotatedType, item: Path, typeSupported: Predicate<Class<*>>): Any {

0 commit comments

Comments
Ā (0)