Skip to content

Fix error handling during type autodetection in create mode#91

Open
lxp wants to merge 2 commits intopython3from
fix-create-type-autodetect-error-handling
Open

Fix error handling during type autodetection in create mode#91
lxp wants to merge 2 commits intopython3from
fix-create-type-autodetect-error-handling

Conversation

@lxp
Copy link
Member

@lxp lxp commented Mar 8, 2026

When specifying an unknown filename without type in create mode the exception is not handled correctly:

$ cfv -C -f asdf
Traceback (most recent call last):
  File "/persist/cfv/test/cfv", line 9, in <module>
    cfv.common.main()
    ~~~~~~~~~~~~~~~^^
  File "/persist/cfv/lib/cfv/common.py", line 2314, in main
    raise CFVValueError('specify a filetype with -t, or use standard extension')
cfv.exceptions.CFVValueError: specify a filetype with -t, or use standard extension

This fix handles and displays the error correctly:

$ cfv -C -f asdf
cfv: specify a filetype with -t, or use standard extension

When specifying an unknown filename without type in create mode
the exception is not handled correctly:

$ cfv -C -f asdf
Traceback (most recent call last):
  File "/persist/cfv/test/cfv", line 9, in <module>
    cfv.common.main()
    ~~~~~~~~~~~~~~~^^
  File "/persist/cfv/lib/cfv/common.py", line 2314, in main
    raise CFVValueError('specify a filetype with -t, or use standard extension')
cfv.exceptions.CFVValueError: specify a filetype with -t, or use standard extension

This fix handles and displays the error correctly:

$ cfv -C -f asdf
cfv: specify a filetype with -t, or use standard extension
@lxp lxp added this to the 3.3 milestone Mar 8, 2026
@sarsolot
Copy link

sarsolot commented Mar 9, 2026

Good catch, had it on my TODO as well. One suggestion - instead of replacing the raise with view.perror(...) + sys.exit(1), consider wrapping the post parse execution phase in its own try/except CFVValueError and using the same cfv: ... handler there. That keeps the raise in place and handles these runtime CFVValueErrors in one consistent place.

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

Successfully merging this pull request may close these issues.

2 participants