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

Output error messages when using execute from vpype API #664

Open
ithinkido opened this issue Sep 28, 2023 · 4 comments
Open

Output error messages when using execute from vpype API #664

ithinkido opened this issue Sep 28, 2023 · 4 comments

Comments

@ithinkido
Copy link
Contributor

Would it be possible to get error messages when using the execute command from the vpype cli ?
The use case would be something like this :

error == vp.execute( do something)
      if error:
          print( error)
      else :
            print( "conversion success")
@abey79
Copy link
Owner

abey79 commented Sep 28, 2023

This is a good feature idea. However, it would work using exceptions:

try:
    doc = vp.execute_throw("....", doc)
except Exception:
   pass # handle error here

@abey79 abey79 added this to the 1.14.0 milestone Sep 28, 2023
@ithinkido
Copy link
Contributor Author

Can execption differentiate between errors and info messages ?

@abey79
Copy link
Owner

abey79 commented Oct 6, 2023

Info message would continue to go to stdout. Maybe we should have a separate mechanism to capture stdout and make it programmatically available.

@abey79
Copy link
Owner

abey79 commented Jan 7, 2024

A more complete workaround is:

import contextlib
import io

import vpype_cli

try:
    output = io.StringIO()
    with contextlib.redirect_stdout(output):
        vpype_cli.execute("read doesntexist.svg show", global_opt="-vv")
    print("Output")
    print(output.getvalue())
except Exception as e:
    print("Error:")
    print(type(e))
    print(e)

This captures both output and catches errors.

@abey79 abey79 removed this from the 1.14.0 milestone Jan 7, 2024
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

2 participants