From 926fdecd13cb1f892b7d0ca8285d17584b5e448a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 5 Jun 2022 11:54:19 +0200 Subject: [PATCH] fix problematic path handling on windows in error messages --- codeCore/src/prog8/code/core/Position.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/codeCore/src/prog8/code/core/Position.kt b/codeCore/src/prog8/code/core/Position.kt index f4b7032c7..48d271c1a 100644 --- a/codeCore/src/prog8/code/core/Position.kt +++ b/codeCore/src/prog8/code/core/Position.kt @@ -1,13 +1,19 @@ package prog8.code.core +import java.nio.file.InvalidPathException import kotlin.io.path.Path import kotlin.io.path.absolute data class Position(val file: String, val line: Int, val startCol: Int, val endCol: Int) { override fun toString(): String = "[$file: line $line col ${startCol+1}-${endCol+1}]" fun toClickableStr(): String { - val path = Path(file).absolute().normalize() - return "file://$path:$line:$startCol:" + return try { + val path = Path(file).absolute().normalize().toString() + "file://$path:$line:$startCol:" + } catch(x: InvalidPathException) { + // this can occur on Windows when the source origin contains "invalid" characters such as ':' + "file://$file:$line:$startCol:" + } } companion object {