Kosmorro / kosmorro

A program to calculate your ephemerides.
https://kosmorro.space
GNU Affero General Public License v3.0
60 stars 7 forks source link

Crashes for some parameter combinations involving --format and --output #276

Closed Arnaud-D closed 2 years ago

Arnaud-D commented 2 years ago

I have searched for an opened issue and didn't find my bug

Version of Kosmorro

0.10

Version of Python

3.10

Operating system

Linux

Installation source

PyPI

Bug description

When launching with kosmorro --output=ephemeride.pdf, kosmorro crashes with the following trace:

Traceback (most recent call last):
  File "/home/arnaud/.local/bin/kosmorro", line 8, in <module>
    sys.exit(main())
  File "/home/arnaud/.local/lib/python3.10/site-packages/kosmorro/__main__.py", line 316, in main
    sys.exit(run())
  File "/home/arnaud/.local/lib/python3.10/site-packages/kosmorro/__main__.py", line 107, in run
    output_file.write(pdf_content)
TypeError: a bytes-like object is required, not 'str'

I would expect an error for missing/wrong parameters instead of a crash.

Alternatively, kosmorro could guess the desired output based on the extension of the output argument, and inform the user that this decision has been made.


Also, kosmorro --format=json --output=ephemeride.json and kosmorro --format=text --output="ephemeride.txt" crash with similar errors.

Here the expected behavior would be to write a file with the json or text output.

Alternatively kosmorro could ignore the parameter and warn the user about it.


For comparison, the following commands works fine:

kosmorro --format=pdf --output=ephemeride.pdf
kosmorro --format=json
kosmorro --format=text
Deuchnord commented 2 years ago

Alternatively, kosmorro could guess the desired output based on the extension of the output argument, and inform the user that this decision has been made.

This is already implemented and will be available in v1.0 (#197) :)

Thanks for the bug report, I'll check what's happening there

Deuchnord commented 2 years ago

After some testing, it looks like the issue described here does not happen in the development branch for v1.0, so I don't think it's worth a fix for v0.10. As a workaround, you may redirect the output with the shell:

kosmorro --format=json > output.json

@Arnaud-D Does it sound good for you?

Arnaud-D commented 2 years ago

Sounds good. :+1: