changeset 1774:764723436f05

better json_parse exception
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Jul 2023 17:24:49 -0600
parents b914a726061f
children e380ab6c0c78
files src/goodjava/parser/ParseException.java src/luan/modules/Parsers.luan
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r b914a726061f -r 764723436f05 src/goodjava/parser/ParseException.java
--- a/src/goodjava/parser/ParseException.java	Tue Jul 18 11:56:40 2023 -0600
+++ b/src/goodjava/parser/ParseException.java	Thu Jul 27 17:24:49 2023 -0600
@@ -47,6 +47,10 @@
 		return text.split("\n",-1);
 	}
 
+	public String getSuperMessage() {
+		return super.getMessage();
+	}
+
 	@Override public String getMessage() {
 		String line;
 		int pos;
diff -r b914a726061f -r 764723436f05 src/luan/modules/Parsers.luan
--- a/src/luan/modules/Parsers.luan	Tue Jul 18 11:56:40 2023 -0600
+++ b/src/luan/modules/Parsers.luan	Thu Jul 27 17:24:49 2023 -0600
@@ -25,10 +25,23 @@
 local Table = require "luan:Table.luan"
 local java_to_table_deep = Table.java_to_table_deep or error()
 local JsonParser = require "java:goodjava.json.JsonParser"
+local ParseException = require "java:goodjava.parser.ParseException"
 
 -- converts json string to luan object
 function Parsers.json_parse(s)
-	local obj = JsonParser.parse(s)
+	local obj
+	try
+		obj = JsonParser.parse(s)
+	catch e
+		local java = e.java.getCause()
+		if java~=nil and java.instanceof(ParseException) then
+			e.message = java.getSuperMessage()
+			e.text = java.text or error()
+			e.error_index = java.errorIndex or error()
+			e.high_index = java.highIndex or error()
+		end
+		e.throw()
+	end
 	return type(obj)=="java" and java_to_table_deep(obj) or obj
 end