Help needed for formatting the resulting yaml file

694 views
Skip to first unread message

joe

unread,
Apr 26, 2010, 11:02:05 AM4/26/10
to SnakeYAML
I am dumping objects containing complete stacktraces and want the
resulting file in a human readable way. I already tried different
DumperOptions, but the resulting file keeps messed up.

For a small stacktrace it works perfect:
"note": ""
"stacktrace": |-
java.lang.ArrayIndexOutOfBoundsException: 3
at example.common.TestTry.execute(Testtry.java:17)
at example.common.TestTry.main(Testtry.java:11)

But for bigger ones it starts getting a mess:
"note": ""
"stacktrace": "Exception in thread \"AWT-EventQueue-0\"
java.lang.IllegalArgumentException:\
\ Stacktrace with name Yaml_ParseError already exists.\n\tat
de.tud.stacktraces.dataset.Dataset.save(Dataset.java:31)\n\
\tat
de.tud.stacktraces.collector.Collector.actionPerformed(Collector.java:
62)\n\
\tat javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
\n\tat javax.swing.AbstractButton$Handler.actionPerformed(Unknown\
\ Source)\n\tat
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)\n\
\tat javax.swing.DefaultButtonModel.setPressed(Unknown Source)\n
\tat javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown\
\ Source)\n\tat java.awt.Component.processMouseEvent(Unknown
Source)\n\tat javax.swing.JComponent.processMouseEvent(Unknown\
\ Source)\n\tat java.awt.Component.processEvent(Unknown Source)\n
\tat java.awt.Container.processEvent(Unknown\
\ Source)\n\tat java.awt.Component.dispatchEventImpl(Unknown
Source)\n\tat java.awt.Container.dispatchEventImpl(Unknown\
\ Source)\n\tat java.awt.Component.dispatchEvent(Unknown Source)\n
\tat java.awt.LightweightDispatcher.retargetMouseEvent(Unknown\
\ Source)\n\tat
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)\n\
\tat java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)\n
\tat java.awt.Container.dispatchEventImpl(Unknown\
\ Source)\n\tat java.awt.Window.dispatchEventImpl(Unknown Source)\n
\tat java.awt.Component.dispatchEvent(Unknown\
\ Source)\n\tat java.awt.EventQueue.dispatchEvent(Unknown Source)\n
\tat java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown\
\ Source)\n\tat
java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)\n\
\tat java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)\n\tat\
\ java.awt.EventDispatchThread.pumpEvents(Unknown Source)\n\tat
java.awt.EventDispatchThread.pumpEvents(Unknown\
\ Source)\n\tat java.awt.EventDispatchThread.run(Unknown Source)"

Is there a way to have each line of the stacktrace dumped to one line
in the resulting file? I already set the width property of
DumperOptions to Integer.MAX_VALUE, but the result was that the
complete stacktrace gets dumped to one single line.

--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To post to this group, send email to snakeya...@googlegroups.com.
To unsubscribe from this group, send email to snakeyaml-cor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/snakeyaml-core?hl=en.

Andrey

unread,
Apr 26, 2010, 11:20:49 AM4/26/10
to SnakeYAML
Hi,
can you please post here the code you use for dumping to a YAML
document ?

Why "note" and "stacktrace" are double quoted ?
How do you configure literal scalar (http://yaml.org/spec/1.1/
#id926836) for stacktrace value ?

In general humans have very different requirements for a document to
be readable. Combining different scalar styles in the same document is
not very simple.
Can you may be consider a Template processor ? (http://code.google.com/
p/snakeyaml/wiki/Documentation#Dumping_a_custom_YAML_document)

-
Andrey

joe

unread,
Apr 26, 2010, 11:38:42 AM4/26/10
to SnakeYAML
new Yaml(getDumperOptions()).dump(trace, new FileWriter(file));

where trace is my object with properties note and stacktrace.
My options are these:

private DumperOptions getDumperOptions() {
final DumperOptions options = new DumperOptions();
options.setLineBreak(LineBreak.WIN);
options.setDefaultFlowStyle(FlowStyle.AUTO);
options.setExplicitStart(true);
options.setDefaultScalarStyle(ScalarStyle.LITERAL);
options.setIndent(4);
return options;
}

I am new to yaml and have no idea about template processors.

Andrey

unread,
Apr 26, 2010, 11:56:31 AM4/26/10
to SnakeYAML
Can you please provide a self-contained source which I can run on my
computer ?

-
Andrey


N. B. Have you checked the link I have provided ? Template processors
are not related to YAML. It is just a common way to
create a text document.
This is an example:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyaml/emitter/template/VelocityTest.java

Johannes Lerch

unread,
Apr 26, 2010, 2:39:33 PM4/26/10
to snakeya...@googlegroups.com
I attached a small testcase.

If i run this the output is:
--- !!Test$TestBean
"trace": "Exception in thread \"main\" org.apache.commons.lang.UnhandledException:\
    \ org.apache.commons.lang.UnhandledException: while parsing a block mapping\t\
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:575)\t\
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:162)\tat org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:147)\t\
    at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:227)\t\
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:159)\tat org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:121)\t\
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:104)\tat org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:117)\t\
    at org.yaml.snakeyaml.Loader.load(Loader.java:52)\tat org.yaml.snakeyaml.Yaml.load(Yaml.java:178)\t\
    at de.tud.core.util.YamlHelper.load(YamlHelper.java:"


I checked the link about the template processor, but i have no idea how to use it.


2010/4/26 Andrey <py4...@gmail.com>
test.txt
Test.java

Andrey

unread,
Apr 27, 2010, 4:52:19 AM4/27/10
to SnakeYAML
It is very clear now. Thank you.

According to the spec (http://yaml.org/spec/1.1/#id907281) plain
scalars cannot contain tabs or colon (':')
SnakeYAML cannot overcome this limitation. SnakeYAML is forced to use
quoted scalars.
Leading whitespace is ignored and that is why SnakeYAML puts '\' in
the beginning of each line.
Feel free to experiment here (http://instantyaml.appspot.com/) to see
how it works.

SnakeYAML can better manage the line width. In this particular case we
would expect to keep the lines as they are (and not try to cut them to
have default 80 characters per line).

Unfortunately it does not help you much. I have added a few tests to
see how it works. (http://code.google.com/p/snakeyaml/source/browse/
src/test/java/org/yaml/snakeyaml/representer/DumpStackTraceTest.java)
In the last test (testJavaStackTrace2) there is a TODO to indicate we
have some room for improvement. Please check that it is what you
actually expect to get.(the expectation is in the file
stacktrace1.yaml)

Can you please create an issue for SnakeYAML ? You can state there
that the Java stack trace should be serialized with minimum changes to
the layout.

-
Andrey

joe

unread,
Apr 27, 2010, 5:12:38 AM4/27/10
to SnakeYAML
Thanks.
I created Issue 66 for this enhancement.
Reply all
Reply to author
Forward
0 new messages