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

fix: Exit gracefully on artwork and sourcecode src file access errors #1203

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

kesara
Copy link
Member

@kesara kesara commented Jan 16, 2025

Fixes #1125

@rjsparks
Copy link
Member

This changes the overall behavior to "exit on first error" rather than "list all errors". Is that necessary?
I think #1125 was complaining more about the lack of a human-readable interpretation of what had gone wrong than it was the stack trace hiding the error.

@kesara
Copy link
Member Author

kesara commented Jan 16, 2025

This changes the overall behavior to "exit on first error" rather than "list all errors". Is that necessary? I think #1125 was complaining more about the lack of a human-readable interpretation of what had gone wrong than it was the stack trace hiding the error.

This changes the overall behavior to "exit on first error" rather than "list all errors". Is that necessary? I think #1125 was complaining more about the lack of a human-readable interpretation of what had gone wrong than it was the stack trace hiding the error.

xml2rfc doesn't have a builtin functionality to list errors and not generate an output. (EDIT: This statement is incorrect.)
If we are to list these errors, xml2rfc will output something with empty art work/sourcecode.

EDIT: Exception being the parser, where it list errors and on-certain errors xml2rfc exits. But this happens after the parsing in prep stage.

@cabo
Copy link
Contributor

cabo commented Jan 16, 2025

xml2rfc doesn't have a builtin functionality to list errors and not generate an output.
If we are to list these errors, xml2rfc will output something with empty art work/sourcecode.

Which may be exactly what you want during editing the document.

(FYI, kramdown-rfc does not use src=.)

@kesara kesara marked this pull request as draft January 22, 2025 22:52
@kesara
Copy link
Member Author

kesara commented Jan 22, 2025

The existing behaviour is artwork src= exits with an error without generating output:

/root/xml2rfc/draft-doe-src-00.xml(26): Error: Expected an <artwork> src= file at '/root/xml2rfc/foobar.txt', but no such file exists
Not creating output file due to errors (see above)
Unable to complete processing draft-doe-src-00.xml

The sourcecode src= crashes:

/root/xml2rfc/draft-doe-src-00.xml(26): Error: Expected an <sourcecode> src= file at '/root/xml2rfc/foobar.txt', but no such file exists
Traceback (most recent call last):
  File "/usr/local/bin/xml2rfc", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/xml2rfc/run.py", line 720, in main
    xmlrfc.tree = prep.prep()
  File "/usr/local/lib/python3.10/dist-packages/xml2rfc/writers/preptool.py", line 215, in prep
    tree = self.dispatch(self.selectors)
  File "/usr/local/lib/python3.10/dist-packages/xml2rfc/writers/base.py", line 1933, in dispatch
    func(e, e.getparent())
  File "/usr/local/lib/python3.10/dist-packages/xml2rfc/writers/preptool.py", line 1944, in element_sourcecode
    self.normalize_whitespace(e)
  File "/usr/local/lib/python3.10/dist-packages/xml2rfc/writers/preptool.py", line 196, in normalize_whitespace
    lines = e.text.split('\n')
AttributeError: 'NoneType' object has no attribute 'split'

@kesara
Copy link
Member Author

kesara commented Jan 23, 2025

With c4a4a0e, sourcecode src= exits gracefully similar to artwork src=.

@kesara kesara marked this pull request as ready for review January 23, 2025 01:13
@kesara
Copy link
Member Author

kesara commented Jan 23, 2025

Proposed change lists all the errors before exiting:

/root/xml2rfc/draft-doe-src-00.xml(27): Error: Expected an <artwork> src= file at '/root/xml2rfc/foobar.txt', but no such file exists
/root/xml2rfc/draft-doe-src-00.xml(26): Error: Expected an <sourcecode> src= file at '/root/xml2rfc/foobar.txt', but no such file exists
Not creating output file due to errors (see above)
Unable to complete processing draft-doe-src-00.xml

@rjsparks
Copy link
Member

This is incremental improvement, so we should take it.
But we should have a separate issue that tracks letting the run go further, collecting errors along the way, so that users don't have to run the program repeatedly to find all the errors.

@kesara
Copy link
Member Author

kesara commented Jan 23, 2025

This is incremental improvement, so we should take it. But we should have a separate issue that tracks letting the run go further, collecting errors along the way, so that users don't have to run the program repeatedly to find all the errors.

xml2rfc is already doing that in preptool stage, my initial statement was incorrect. I've updated comment.1

Proposed change will follow the same pattern. See output in #1203 (comment)

Footnotes

  1. https://github.com/ietf-tools/xml2rfc/pull/1203#issuecomment-2596855989

@kesara kesara merged commit ce2bde9 into ietf-tools:main Jan 23, 2025
18 checks passed
@kesara kesara deleted the fix/src branch January 23, 2025 21:07
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.

Missing file reported poorly for <sourcecode src=...>
3 participants