ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
68 stars 38 forks source link

Missing file reported poorly for <sourcecode src=...> #1125

Open jennifer-richards opened 4 months ago

jennifer-richards commented 4 months ago

Describe the issue

Encountered in debugging https://github.com/ietf-tools/datatracker/issues/7405, a missing file referred to by the src attribute in a <sourcecode> element results in

/Users/jennifer/ietf/tmp/draft-ietf-sidrops-aspa-profile.xml(169): Error: Expected an <sourcecode> src= file at '/Users/jennifer/ietf/tmp/RPKI-ASPA-2023.asn', but no such file exists
Traceback (most recent call last):
  File "/Users/jennifer/Library/Python/3.11/bin/xml2rfc", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/jennifer/Library/Python/3.11/lib/python/site-packages/xml2rfc/run.py", line 727, in main
    xmlrfc.tree = prep.prep()
                  ^^^^^^^^^^^
  File "/Users/jennifer/Library/Python/3.11/lib/python/site-packages/xml2rfc/writers/preptool.py", line 220, in prep
    tree = self.dispatch(self.selectors)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jennifer/Library/Python/3.11/lib/python/site-packages/xml2rfc/writers/base.py", line 1931, in dispatch
    func(e, e.getparent())
  File "/Users/jennifer/Library/Python/3.11/lib/python/site-packages/xml2rfc/writers/preptool.py", line 1952, in element_sourcecode
    self.normalize_whitespace(e)
  File "/Users/jennifer/Library/Python/3.11/lib/python/site-packages/xml2rfc/writers/preptool.py", line 201, in normalize_whitespace
    lines = e.text.split('\n')
            ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

There is a reasonable error at the top, but it's hidden before the stack trace and unhelpful details about a follow-on exception.

Really ought to end with "no such file exists" (and perhaps clean up the syntax of that error a bit)

Code of Conduct