kazurayam / materialstore

A domain-specific file system to store "materials" (screenshots, HTML, JSON, XML) collected during End-to-End testings using Selenium WebDriver etc. Features to make "diff" and compiling HTML reports are also included. This is written in pure Java8
Apache License 2.0
0 stars 0 forks source link

com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 15 path $. at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1568) #398

Closed kazurayam closed 1 year ago

kazurayam commented 1 year ago

On Windows 10 PC, I got the following error

2022-12-17 22:05:44.593 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - step4_report started
2022-12-17 22:05:45.053 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - step4_report finished
2022-12-17 22:05:45.055 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - step5_backupLatest started
2022-12-17 22:05:45.339 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/CURA/main FAILED.
Reason:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 15 path $.
    at com.google.gson.Gson.fromJson(Gson.java:903)
    at com.google.gson.Gson.fromJson(Gson.java:853)
    at com.google.gson.Gson.fromJson(Gson.java:802)
    at com.kazurayam.materialstore.core.filesystem.TemplateReady.toTemplateModel(TemplateReady.java:20)
    at com.kazurayam.materialstore.base.report.IndexCreator.create(IndexCreator.java:61)
    at com.kazurayam.inspectus.core.internal.AbstractService.step5_backupLatest(AbstractService.java:105)
    at com.kazurayam.inspectus.core.internal.AbstractService.postProcess(AbstractService.java:54)
    at com.kazurayam.inspectus.core.Inspectus.execute(Inspectus.java:13)
    at com.kazurayam.inspectus.core.Inspectus$execute.call(Unknown Source)
    at main.run(main:43)
    at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
    at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
    at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
    at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
    at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
    at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
    at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
    at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
    at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
    at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
    at TempTestCase1671282265171.run(TempTestCase1671282265171.groovy:25)
Caused by: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 15 path $.
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1568)
    at com.google.gson.stream.JsonReader.readEscapeCharacter(JsonReader.java:1559)
    at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1014)
    at com.google.gson.stream.JsonReader.nextString(JsonReader.java:815)
    at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:76)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
    at com.google.gson.Gson.fromJson(Gson.java:888)
    at com.google.gson.Gson.fromJson(Gson.java:853)
    at com.google.gson.Gson.fromJson(Gson.java:802)
    at com.kazurayam.materialstore.core.filesystem.TemplateReady.toTemplateModel(TemplateReady.java:20)
    at com.kazurayam.materialstore.base.report.IndexCreator.create(IndexCreator.java:61)
    at com.kazurayam.inspectus.core.internal.AbstractService.step5_backupLatest(AbstractService.java:105)
    at com.kazurayam.inspectus.core.internal.AbstractService.postProcess(AbstractService.java:54)
    at com.kazurayam.inspectus.core.Inspectus.execute(Inspectus.java:13)
    at com.kazurayam.inspectus.core.Inspectus$execute.call(Unknown Source)
    at Script1667709715867.run(Script1667709715867.groovy:43)
    ... 11 more

2022-12-17 22:05:45.362 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/CURA/main FAILED.
Reason:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 15 path $.
    at com.google.gson.Gson.fromJson(Gson.java:903)
    at com.google.gson.Gson.fromJson(Gson.java:853)
    at com.google.gson.Gson.fromJson(Gson.java:802)
    at com.kazurayam.materialstore.core.filesystem.TemplateReady.toTemplateModel(TemplateReady.java:20)
    at com.kazurayam.materialstore.base.report.IndexCreator.create(IndexCreator.java:61)
    at com.kazurayam.inspectus.core.internal.AbstractService.step5_backupLatest(AbstractService.java:105)
    at com.kazurayam.inspectus.core.internal.AbstractService.postProcess(AbstractService.java:54)
    at com.kazurayam.inspectus.core.Inspectus.execute(Inspectus.java:13)
    at com.kazurayam.inspectus.core.Inspectus$execute.call(Unknown Source)
    at main.run(main:43)
    at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
    at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
    at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
    at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
    at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
    at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
    at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
    at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
    at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
    at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
    at TempTestCase1671282265171.run(TempTestCase1671282265171.groovy:25)
Caused by: com.google.gson.stream.MalformedJsonException: Invalid escape sequence at line 1 column 15 path $.
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1568)
    at com.google.gson.stream.JsonReader.readEscapeCharacter(JsonReader.java:1559)
    at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1014)
    at com.google.gson.stream.JsonReader.nextString(JsonReader.java:815)
    at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:76)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
    at com.google.gson.Gson.fromJson(Gson.java:888)
    ... 20 more

2022-12-17 22:05:45.365 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/CURA/main
kazurayam commented 1 year ago

I need to see the malformed json instance.

kazurayam commented 1 year ago

In the IndexCreater, there is following code.

      @Override
        public String toJson(){
            StringBuilder sb = new StringBuilder();
            sb.append("{").append("\"store\":\"")
                    .append(store.getRoot().toString()).append("\"")
                    ...

store.getRoot().toString() includes for example "C:\Users\kazurayam\tmp\MyProject\store..." on Windows. The backslash character ( \ ) must be escaped to be avalid JSON string.

kazurayam commented 1 year ago

I will use com.kazurayam.materialstore.core.util.JsonUtil.escapeAsJsonString(String) to escape a string to be a valid JSON string.

kazurayam commented 1 year ago

done at 0.14.3