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

differences in output between -pipe and and input puml file prints ERROR #155

Closed
janitha09 opened this issue Dec 7, 2018 · 7 comments
Closed

Comments

@janitha09
Copy link

Using pipe the output looks like this
$ echo -e "@startuml\nAlice -> Bob: test\n@enduml\n" | java -Djava.awt.headless=true -jar plantuml.jar -v -pipe > alice.png

(0.001 - 256 Mo) 250 Mo - PlantUML Version 1.2018.13
(0.006 - 256 Mo) 250 Mo - GraphicsEnvironment.isHeadless() true
(0.006 - 256 Mo) 250 Mo - Forcing -Djava.awt.headless=true
(0.006 - 256 Mo) 250 Mo - java.awt.headless set as true
(0.007 - 256 Mo) 250 Mo - Forcing resource load on OpenJdk
(0.974 - 256 Mo) 248 Mo - Setting current dir: .
(0.979 - 256 Mo) 248 Mo - Reading from string
(0.980 - 256 Mo) 248 Mo - Creating AParentFolderRegular .
(1.637 - 312 Mo) 250 Mo - Creating image 119x127
(1.677 - 312 Mo) 249 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata
(1.718 - 312 Mo) 248 Mo - Reading from string
(1.718 - 312 Mo) 248 Mo - Creating AParentFolderRegular .
(1.963 - 312 Mo) 140 Mo - Creating image 535x276
(2.031 - 442 Mo) 309 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata
ERROR
0
Empty description
Some diagram description contains errors

Using a file input makes no difference
$ echo -e "@startuml\nAlice -> Bob: test\n@enduml\n" > alice.puml
$ cat alice.puml | java -Djava.awt.headless=e -jar ./plantuml.jar -v -pipe > alice.png

(0.000 - 256 Mo) 250 Mo - PlantUML Version 1.2018.13
(0.006 - 256 Mo) 250 Mo - GraphicsEnvironment.isHeadless() false
(0.006 - 256 Mo) 250 Mo - Forcing resource load on OpenJdk
(1.034 - 256 Mo) 248 Mo - Setting current dir: .
(1.039 - 256 Mo) 247 Mo - Reading from string
(1.040 - 256 Mo) 247 Mo - Creating AParentFolderRegular .
(1.671 - 256 Mo) 193 Mo - Creating image 119x127
(1.704 - 256 Mo) 192 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata
(1.746 - 256 Mo) 191 Mo - Reading from string
(1.746 - 256 Mo) 191 Mo - Creating AParentFolderRegular .
(2.083 - 312 Mo) 162 Mo - Creating image 535x276
(2.121 - 312 Mo) 135 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata```
ERROR
0
Empty description
Some diagram description contains errors

Using the same file as an input
$ java -Djava.awt.headless=true -jar ./plantuml.jar -v alice.puml

(0.000 - 256 Mo) 250 Mo - PlantUML Version 1.2018.13
(0.003 - 256 Mo) 250 Mo - GraphicsEnvironment.isHeadless() true
(0.004 - 256 Mo) 250 Mo - Forcing -Djava.awt.headless=true
(0.004 - 256 Mo) 250 Mo - java.awt.headless set as true
(0.004 - 256 Mo) 250 Mo - Forcing resource load on OpenJdk
(1.064 - 256 Mo) 248 Mo - Found 1 files
(1.064 - 256 Mo) 248 Mo - Working on .
(1.085 - 256 Mo) 247 Mo - Setting current dir: .
(1.085 - 256 Mo) 247 Mo - Setting current dir: xxxx
(1.086 - 256 Mo) 247 Mo - Using default charset
(1.089 - 256 Mo) 247 Mo - Reading from alice.puml
(1.090 - 256 Mo) 247 Mo - Creating AParentFolderRegular xxx
(1.104 - 256 Mo) 246 Mo - Reading file: alice.puml
(1.565 - 256 Mo) 171 Mo - Creating file: xxx/alice.png
(1.600 - 256 Mo) 169 Mo - Creating image 119x127
(1.632 - 256 Mo) 167 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata
(1.673 - 256 Mo) 166 Mo - File size : 3293
(1.674 - 256 Mo) 166 Mo - Number of image(s): 1

In each of the above cases the png is generated and it renders.

Is there a reason why the output messages need to be different? I only care about this because I am parsing errors in python for a git hook and would like a way to test the error conditions in my tests. It would be nice to not have to create a file per test.

You do seem to be able to generate a diagram with the @startuml tags when pipe is used and not when it is an input file - is this desired behavior?

$ echo -e "Alice -> Bob: test\n" | java -Djava.awt.headless=true -jar ./plantuml.jar -v -pipe > alice.png

(0.000 - 256 Mo) 250 Mo - PlantUML Version 1.2018.13
(0.006 - 256 Mo) 250 Mo - GraphicsEnvironment.isHeadless() true
(0.006 - 256 Mo) 250 Mo - Forcing -Djava.awt.headless=true
(0.007 - 256 Mo) 250 Mo - java.awt.headless set as true
(0.007 - 256 Mo) 250 Mo - Forcing resource load on OpenJdk
(1.062 - 256 Mo) 248 Mo - Setting current dir: .
(1.067 - 256 Mo) 248 Mo - Reading from string
(1.068 - 256 Mo) 248 Mo - Creating AParentFolderRegular .
(1.644 - 256 Mo) 175 Mo - Creating image 119x127
(1.678 - 256 Mo) 173 Mo - Ok for com.sun.imageio.plugins.png.PNGMetadata

I have done some editing of the output as to hide the full path in the output

@janitha09 janitha09 changed the title different in output between -pipe and and input.puml file differences in output between -pipe and and input puml file Dec 7, 2018
@arnaudroques
Copy link
Contributor

Hi,
About @startuml tags needed or not when pipe is used, there is a long answer on http://plantuml.com/faq

Long answer:

The @startuml/@startditaa/@startjcckit is useful to determine the type of diagram (uml, ditaa, jcckit...), and because you can optionally put a filename after the @startxxx. This also allows to have several diagrams inside the same file.

Earlier versions of PlantUML were not supporting ditaa or jcckit. When you use -pipe flag, since the diagram is generated to standard output, there could be only one diagram in the standard input. And there is no need to specify a filename. For all those reasons, @startuml was not needed when using -pipe flag at that time.

Latter, it has been decided to normalize this, and to impose @startxxx everywhere, even with -pipe flag, because it was confusing for users. Unfortunately, since some existing scripts were already using the fact that @startuml is not needed in -pipe flag, it has been decided to keep this as a deprecated option, just to allow older scripts to run. We indeed do pay attention of ascending compatibility.

For newer scripts, you should not rely on this, and use @startXXX/@Endxxx with the -pipe flag.

Hope it helps!

Is there a reason why the output messages need to be different?

Well, the ouput messages are different because the input is different.

When using -pipe option, no file is actually read from the FileSystem (from a JVM point of view)
When using a file name, a regular file is really read from the FileSystem, so we print its path to help any debug issue (note that you have used the -v option which mean verbose).

Printing a path with -pipe option would really have no sense, because there is no file read and no path to be printed.

But it's not because we do not print path using -pipe option that we should not print them when using filename (when it does mean something).

I only care about this because I am parsing errors in python for a git hook and would like a way to test the error conditions in my tests. It would be nice to not have to create a file per test.

I understand your need. Maybe it's time for us to add some level of trace. The default level would be the actual one, but we can think about a -v0 option flag that would be a little less verbose (without any file path for example) and that would print the same information using -pipe or file.
Does it sound good to you ?
If it does, maybe you could post here your expected trace using this future -v0 flag. Thanks!

@janitha09 janitha09 changed the title differences in output between -pipe and and input puml file differences in output between -pipe and and input puml file prints ERROR Dec 9, 2018
@janitha09
Copy link
Author

Thanks for the detailed explanation about -pipe. My concern should have been clearer.

my "working" code looks like this:

    def generate_png(self, input, output):
        command = self.java_jar + self.puml + " -v " + input + " -o " + self.output_dir
        pprint("I am going to run the following command: " + command +
               ". This is so that I can verify that no errors will occur on the build that will publish everyones diagrams")
        p_generate = subprocess.Popen(
            [command], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
        retval = p_generate.wait()
        stdout_lines = p_generate.stdout.readlines()
        pprint(stdout_lines)
        if retval > 0:
            pprint("I think some thing is wrong with your file - very likely a syntax error, check the generated file if there was one per the log above")
            return retval
        error_hints = ['error', 'errors', 'Error', 'Errors', 'cannot', 'Found 0 files',
                       'Exception', 'Warning: no image in']
        matching = [s for s in stdout_lines if any(
            xs in s for xs in error_hints)]
        if len(matching) > 0:
            pprint("I found a message that indicates a failure: " +
                   '\n'.join(matching))
            retval = 1
        return retval

my gripe is with these lines that are printed out only when -pipe is used:

ERROR
0
Empty description
Some diagram description contains errors

ERROR is printed out, I assume the 0 is the return value.

I can't depend on the error code because a file not found returns 0 - I want it to return 1. Per the above printout from the output of -pipe I can't depend on "ERROR" either. I have tried to work around it by grepping all the log.error and looking for messages that I think I would care about. Then Log.info also has "error" in its text.

the calling code looks like this - for completeness

def test_generate_png_syntax_error():
    pre_commit = Pre_Commit(
        './plantuml.jar',
        './temp')
    retval = pre_commit.generate_png(
        './alice_syntax_error.puml', './temp')
    assert_equals(retval, 1)

@arnaudroques
Copy link
Contributor

Thanks also for your explanation, it's more clear for us too!

Unfortunately we cannot change the actual behavior of the command line because some plugins really depend on this, and will be break by any change.

However, we agree that it's time to design the command line interface, so we come with a proposal.

In last beta http://beta.plantuml.net/plantuml.jar we've added a new flag -stdrpt (as standard report) that does output on standard error stream the following info:

protocolVersion=1
status=ERROR
lineNumber=1
label=Syntax error: foo

This is printed whether you use the -pipe flag or not (but remember you have to also put -stdrpt)

You really should not use -v flag as output information can change from version to version without notice.

However, once it will be fully specified, -stdrpt will remain stable over time.
We are going to version the protocol itself (that's why you have protocolVersion=1) and you will be able in the future to force a specific version to be used (with -stdrpt:1 )

Tell us if some information are missing for you, we will add them.
Note that this has not been widely tested, so feedback is welcome.

@janitha09
Copy link
Author

janitha09 commented Dec 10, 2018

Thank you for the heads up about verbose (I think it is helpful to tell the user why I decided to get in the way of their work).

The KVP is easier to read and parse.

I am using openjdk so I can't build your code. I have an issue similar to #69 while attempting to build - I can probably find a oracle jdk on a docker container.

$ java -Djava.awt.headless=true -jar ./plantuml_beta.jar -stdrpt ./inventorysales.puml

protocolVersion=1
status=ERROR
lineNumber=2
label=Syntax Error?

Error line 2 in file: ./inventorysales.puml

Some diagram description contains errors

The exit code is good

$ echo $?
1

Using the same file with the same error in pipe

$ cat ./inventorysales.puml | java -Djava.awt.headless=true -jar ./plantuml_beta.jar -stdrpt -pipe > inventory.png

protocolVersion=1
status=ERROR
lineNumber=2
label=Syntax Error?
Some diagram description contains errors

notice the missing lines in bold above. I think it's polite to tell the consumer everything they need to do to fix the problem. In this case I misspelled participant

The exit code is good

$ echo $?
1

@janitha09
Copy link
Author

From the original post I do not understand why this is an error

$echo -e "@startuml\nAlice -> Bob: test\n@enduml\n" | java -Djava.awt.headless=true -jar /Users/janithajayaweera/Downloads/plantuml_beta.jar -pipe -stdrpt > alice.png

protocolVersion=1
status=NO_DATA
lineNumber=0
label=Empty description
Some diagram description contains errors

exit code

echo $?
1

@janitha09
Copy link
Author

closing no longer at the company that this was a problem for

@fuhrmanator
Copy link

Hi @arnaudroques -- Is this related to qjebbs/vscode-plantuml#265 ? When a diagram is previewed without having @enduml in the text, the extension in VSCode shows "no @startuml" which is a misleading error (since it should say "no @enduml".

You can try it yourself with the VSCode extension for plantuml (it's very cool).

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

No branches or pull requests

3 participants