relaton / relaton-iso

RelatonIso: ISO Standards metadata using the BibliographicItem model
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

(URGENT) Do not crash when unable to parse document identifier #126

Closed ronaldtse closed 2 years ago

ronaldtse commented 2 years ago

From https://github.com/metanorma/iso-19135/issues/24

"ISO/TC 211 Good Practices" is not meant to be a standards identifier. However when Relaton parses it, it crashes. It should instead just provide a "not found" output.

$ bundle exec relaton fetch "ISO/TC 211 Good Practices"
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
bundler: failed to load command: relaton (ruby/3.1.2/bin/relaton)
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/pubid-core-0.2.2/lib/pubid/core/identifier.rb:93:in `rescue in parse': Failed to match sequence (stage:'Fpr'? 'WD/'? (type:GUIDE_PREFIX SPACE)? (stage:STAGE SPACE)? ORIGINATOR (SPACE / '/') (TC_DOCUMENT_BODY / STD_DOCUMENT_BODY / DIR_DOCUMENT_BODY (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY))?)) at line 1 char 5. (Pubid::Core::Errors::ParseError)
cause: Failed to match sequence (stage:'Fpr'? 'WD/'? (type:GUIDE_PREFIX SPACE)? (stage:STAGE SPACE)? ORIGINATOR (SPACE / '/') (TC_DOCUMENT_BODY / STD_DOCUMENT_BODY / DIR_DOCUMENT_BODY (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY))?)) at line 1 char 5.
`- Expected one of [TC_DOCUMENT_BODY, STD_DOCUMENT_BODY, DIR_DOCUMENT_BODY (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY))?] at line 1 char 5.
   |- Failed to match sequence ((tctype:TCTYPE '/'?){0, } SPACE tcnumber:DIGITS ('/' ((sctype:SCTYPE SPACE scnumber:DIGITS '/')? wgtype:WGTYPE SPACE wgnumber:DIGITS / sctype:SCTYPE (SPACE / '/' wgtype:WGTYPE SPACE) scnumber:DIGITS))? SPACE 'N' SPACE? number:DIGITS) at line 1 char 12.
   |  `- Expected "N", but got "G" at line 1 char 12.
   |- Failed to match sequence ((TYPE / stage:STAGE)? SPACE? ((stage:STAGE / TYPE) SPACE)? number:DIGITS ('|' joint_document:('IDF' SPACE DIGITS))? PART? ITERATION? (SPACE? (':' / '-') YEAR)? (AMENDMENT CORRIGENDUM? / CORRIGENDUM)? EDITION? LANGUAGE?) at line 1 char 5.
   |  `- Expected at least 1 of \\\\d at line 1 char 5.
   |     `- Failed to match \\\\d at line 1 char 5.
   `- Failed to match sequence (DIR_DOCUMENT_BODY (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY))?) at line 1 char 5.
      `- Extra input after last repetition at line 1 char 5.
         `- Failed to match sequence (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY)) at line 1 char 5.
            `- Expected " + ", but got "TC " at line 1 char 5.
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/pubid-core-0.2.2/lib/pubid/core/identifier.rb:68:in `parse'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-iso-1.12.4/lib/relaton_iso/iso_bibliography.rb:38:in `get'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-iso-1.12.4/lib/relaton_iso/processor.rb:19:in `get'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:187:in `fetch_doc'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:467:in `net_retry'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:436:in `new_bib_entry'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:400:in `check_bibliocache'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:64:in `fetch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli/command.rb:183:in `fetch_document'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli/command.rb:31:in `fetch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-hollaback-0.2.1/lib/thor/hollaback.rb:71:in `block in run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/hollaback-0.1.1/lib/hollaback/sequence.rb:34:in `call'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-hollaback-0.2.1/lib/thor/hollaback.rb:71:in `run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli.rb:41:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/exe/relaton:20:in `<top (required)>'
    from ruby/3.1.2/bin/relaton:25:in `load'
    from ruby/3.1.2/bin/relaton:25:in `<top (required)>'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:484:in `exec'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:31:in `dispatch'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:25:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:48:in `block in <top (required)>'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/friendly_errors.rb:103:in `with_friendly_errors'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:36:in `<top (required)>'
    from ruby/3.1.2/bin/bundle:25:in `load'
    from ruby/3.1.2/bin/bundle:25:in `<main>'
ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/cause.rb:70:in `raise': Failed to match sequence (stage:'Fpr'? 'WD/'? (type:GUIDE_PREFIX SPACE)? (stage:STAGE SPACE)? ORIGINATOR (SPACE / '/') (TC_DOCUMENT_BODY / STD_DOCUMENT_BODY / DIR_DOCUMENT_BODY (' + ' joint_document:(ORIGINATOR SPACE DIR_DOCUMENT_BODY))?)) at line 1 char 5. (Parslet::ParseFailed)
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/parslet-2.0.0/lib/parslet/atoms/base.rb:49:in `parse'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/pubid-core-0.2.2/lib/pubid/core/identifier.rb:70:in `parse'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-iso-1.12.4/lib/relaton_iso/iso_bibliography.rb:38:in `get'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-iso-1.12.4/lib/relaton_iso/processor.rb:19:in `get'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:187:in `fetch_doc'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:467:in `net_retry'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:436:in `new_bib_entry'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:400:in `check_bibliocache'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-1.12.4/lib/relaton/db.rb:64:in `fetch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli/command.rb:183:in `fetch_document'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli/command.rb:31:in `fetch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-hollaback-0.2.1/lib/thor/hollaback.rb:71:in `block in run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/hollaback-0.1.1/lib/hollaback/sequence.rb:34:in `call'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-hollaback-0.2.1/lib/thor/hollaback.rb:71:in `run'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/lib/relaton/cli.rb:41:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/relaton-cli-1.12.1/exe/relaton:20:in `<top (required)>'
    from ruby/3.1.2/bin/relaton:25:in `load'
    from ruby/3.1.2/bin/relaton:25:in `<top (required)>'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:484:in `exec'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:31:in `dispatch'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:25:in `start'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:48:in `block in <top (required)>'
    from ruby/3.1.2/lib/ruby/3.1.0/bundler/friendly_errors.rb:103:in `with_friendly_errors'
    from ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:36:in `<top (required)>'
    from ruby/3.1.2/bin/bundle:25:in `load'
    from ruby/3.1.2/bin/bundle:25:in `<main>'

However, this error should not be shown, because it is not an ISO document.

We should just say that:

[relaton] "ISO/TC 211 Good Practices" is not recognized as a standards identifier.