zeldigas / text2confl

Publisher of documents to confluence
Apache License 2.0
12 stars 2 forks source link

Text2confl crashes when header-0 uses an attribute #176

Closed feliksik closed 3 months ago

feliksik commented 5 months ago

Actual Behavior

The following document makes text2confl crash:

= {my-product}
:my-product: Whizbang Product

My Content
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('m' (code 109)): was expecting double-quote to start field name
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 3]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2481)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:752)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:676)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddName(ReaderBasedJsonParser.java:1943)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextFieldName(ReaderBasedJsonParser.java:972)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:596)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:449)
    at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:32)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4899)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3846)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3829)
    at com.github.zeldigas.text2confl.convert.PageAttributesKt.parseAttribute(PageAttributes.kt:25)
    at com.github.zeldigas.text2confl.convert.asciidoc.AsciidocFileConverter.toHeader(AsciidocFileConverter.kt:20)
    at com.github.zeldigas.text2confl.convert.asciidoc.AsciidocFileConverter.readHeader(AsciidocFileConverter.kt:16)
    at com.github.zeldigas.text2confl.convert.UniversalConverter$scanDocuments$2.invoke(Converter.kt:114)

Expected Behavior

One can use a variable to start the title, as this is valid asciidoc.

Second thing is that if something unexpected fails, the exception mentions the .adoc file that triggered the failure.

Analysis

Cause

The attributes are parsed here. The assumption that the "{" delimiter indicates yaml/json is not correct: it might well be templated asciidoc.

However, I'm not yet exactly sure why this works:

= xyz
:my-product: Whizbang Product
:a: {my-product}

The Content {a}

It has to do with the fact that asciidoctor is using the header-0 = {my-product} to set the :title: attribute, which is consequently parsed by text2conf.

It would be useful to use a title from a variable.

Workaround

Use a   prefix for title:

=   {my-product}
:my-product: Whizbang Product

My Content
zeldigas commented 3 months ago

@feliksik fixed and released as 0.17.0

feliksik commented 3 months ago

You are great, thanks!

feliksik commented 3 months ago

It turns out that text2confl also needs to catch a JsonMappingException; When any variable is enclosed in [ and ], that's the one that's thrown:

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Unrecognized token 'x': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 3] (through reference chain: java.util.ArrayList[0])
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:373)
    at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:223)
    at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:184)
    at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:27)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3848)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3831)
    at com.github.zeldigas.text2confl.convert.PageAttributesKt.parseAttribute(PageAttributes.kt:36)
    at com.github.zeldigas.text2confl.convert.asciidoc.AsciidocFileConverter.toHeader(AsciidocFileConverter.kt:20)
    at com.github.zeldigas.text2confl.convert.asciidoc.AsciidocFileConverter.readHeader(AsciidocFileConverter.kt:16)
    at com.github.zeldigas.text2confl.convert.UniversalConverter.scanDocuments$lambda$6(Converter.kt:113)
    at com.github.zeldigas.text2confl.convert.FileNameBasedDetector.scanDirectoryRecursively(PagesDetector.kt:29)
    at com.github.zeldigas.text2confl.convert.FileNameBasedDetector.scanDirectoryRecursively(PagesDetector.kt:32)
    at com.github.zeldigas.text2confl.convert.FileNameBasedDetector.scanDirectoryRecursively(PagesDetector.kt:32)
    at com.github.zeldigas.text2confl.convert.UniversalConverter.scanDocuments(Converter.kt:110)
    at com.github.zeldigas.text2confl.convert.UniversalConverter.convertDir(Converter.kt:79)
    at com.github.zeldigas.text2confl.cli.Upload.tryUpload(Upload.kt:89)
    at com.github.zeldigas.text2confl.cli.Upload.access$tryUpload(Upload.kt:27)
    at com.github.zeldigas.text2confl.cli.Upload$run$1.invokeSuspend(Upload.kt:74)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at com.github.zeldigas.text2confl.cli.Upload.run(Upload.kt:71)
    at com.github.ajalt.clikt.parsers.Parser.finalizeAndRun(Parser.kt:348)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:218)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:245)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:42)
    at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:457)
    at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:454)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:474)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:481)
    at com.github.zeldigas.text2confl.cli.MainKt.main(Main.kt:42)

I actually ran into this when using some plantUML in a variable.

zeldigas commented 3 months ago

Fixed in 0.17.1