Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode-json + catch-object-exception + open-http turns something into an error which is none #584

Open
TobiasNx opened this issue Dec 12, 2024 · 2 comments
Labels

Comments

@TobiasNx
Copy link
Contributor

TobiasNx commented Dec 12, 2024

https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-lines%0A%7C+catch-object-exception+%0A%7C+open-http%0A%7C+as-records%0A%7C+decode-json%0A%7C+list-fix-values%28%22type%5B%5D%22%29%0A%7C+print%0A%3B%0A&data=https%3A//lobid.org/resources/1188059580.json%0Ahttps%3A//lobid.org/resources/HT020467687.json

file content, first link provides no json but a Error message second does and is not broken:

https://lobid.org/resources/1188059580.json
https://lobid.org/resources/HT020467687.json
inputFile
| open-file
| as-lines
| catch-object-exception 
| open-http
| as-records
| decode-json
| list-fix-values("type[]")
| print
;

When running it on the command line the following exception with two erros returns:

$ '/home/tobias/Downloads/metafix-runner-1.1.2/bin/metafix-runner' '/home/tobias/git/metafacture_workflows/rpbArticleRelatiedTypeInLobid/lobidTypeTesterForRpb.flux'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/tobias/Downloads/metafix-runner-1.1.2/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/tobias/Downloads/metafix-runner-1.1.2/lib/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory]
0    [main] ERROR .flowcontrol.ObjectExceptionCatcher  - 'com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ERROR': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"ERROR: "Not found: 1188059580""; line: 1, column: 6]' while processing object: https://lobid.org/resources/1188059580.json
114  [main] ERROR .flowcontrol.ObjectExceptionCatcher  - 'com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ERROR': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"ERROR: "Not found: 1188059580"{
  "@context" : "http://lobid.org/resources/context.jsonld",
  "id" : "http://lobid.org/resources/990366605490206441#!",
  "type" : [ "BibliographicResource", "Book" ],
  "medium" : [ {
    "label" : "Print",
    "id" : "http://rdaregistry.info/termList/RDAproductionMethod/1010"
  } ],
  "title" : "Weinfreunde Marx & Engels",
  "almaMmsId" : "990366605490206441",
  "hbzId" : "HT020467687",
  "deprecatedUri" : "http://lobid.org/resources/HT020467687#!",
  "isbn" : ["[truncated 14186 chars]; line: 1, column: 6]' while processing object: https://lobid.org/resources/HT020467687.json
0       |

If the exception catcher is outcommented the process only returns one error:

Exception in thread "main" org.metafacture.framework.MetafactureException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ERROR': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"ERROR: "Not found: 1188059580""; line: 1, column: 6]
        at org.metafacture.json.JsonDecoder.processRecord(JsonDecoder.java:250)
        at org.metafacture.json.JsonDecoder.process(JsonDecoder.java:235)
        at org.metafacture.json.JsonDecoder.process(JsonDecoder.java:45)
        at org.metafacture.io.RecordReader.emitRecord(RecordReader.java:144)
        at org.metafacture.io.RecordReader.process(RecordReader.java:132)
        at org.metafacture.io.RecordReader.process(RecordReader.java:40)
        at org.metafacture.io.HttpOpener.process(HttpOpener.java:306)
        at org.metafacture.io.HttpOpener.process(HttpOpener.java:50)
        at org.metafacture.io.LineReader.process(LineReader.java:69)
        at org.metafacture.io.LineReader.process(LineReader.java:55)
        at org.metafacture.io.LineReader.process(LineReader.java:37)
        at org.metafacture.io.FileOpener.process(FileOpener.java:158)
        at org.metafacture.io.FileOpener.process(FileOpener.java:41)
        at org.metafacture.flux.parser.StringSender.process(StringSender.java:43)
        at org.metafacture.flux.parser.Flow.start(Flow.java:118)
        at org.metafacture.flux.parser.FluxProgramm.start(FluxProgramm.java:168)
        at org.metafacture.runner.Flux.main(Flux.java:87)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ERROR': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"ERROR: "Not found: 1188059580""; line: 1, column: 6]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2477)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:760)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:3041)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2082)
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:808)
        at org.metafacture.json.JsonDecoder.decode(JsonDecoder.java:294)
        at org.metafacture.json.JsonDecoder.processRecord(JsonDecoder.java:247)
        ... 16 more

When only using the second link, the transformation works.

@TobiasNx TobiasNx added the Bug label Dec 12, 2024
@TobiasNx
Copy link
Contributor Author

Ha, I moved the exception catcher in front of decode-json, then it works.

Could the exception catcher not properly end its job after open-http?

@TobiasNx TobiasNx changed the title decode-json + catch-object-exception + open-html turns something into an error which is none decode-json + catch-object-exception + open-http turns something into an error which is none Dec 12, 2024
@dr0i
Copy link
Member

dr0i commented Dec 13, 2024

(I had problems to understand your issue, but I will give it a try.)
Your provided links don't work. Seems you have missed %0A at the end of the link , as this works:

https://metafacture.org/playground/?flux=inputFile%0A%7C+open-file%0A%7C+as-lines%0A%7C+catch-object-exception+%0A%7C+open-http%0A%7C+as-records%0A%7C+decode-json%0A%7C+list-fix-values%28%22type%5B%5D%22%29%0A%7C+print%0A%3B%0A&data=https%3A//lobid.org/resources/1188059580.json%0Ahttps%3A//lobid.org/resources/HT020467687.json%0A

The result when query 1188059580.json is empty (as you've written) but no error message is given (at least in the playground it is not). There has to be some kind of error, though, because the input resource ("https://lobid.org/resources/1188059580.json") does not exist and the webserver answers with an exception "Not found: 1188059580" and this is structurally no JSON so cannot be parsed by a JSON parser.

The thing that's smelly IMO is your log message:

"Not found: 1188059580"{
"@context" : "http://lobid.org/resources/context.jsonld",

The output of the resource (starting with @context) does not belong to the first output. At the very least a line break is missing. This is done here .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants