redhataccess / ascii_binder

AsciiBinder is an AsciiDoc-based system for authoring and publishing closely related documentation sets from a single source.
https://asciibinder.net
MIT License
76 stars 39 forks source link

Improve error messages #99

Closed r0ckarong closed 4 years ago

r0ckarong commented 7 years ago

I get error messages that I try to understand but don't make sense until after a lot of experimentation. Maybe you could add some exception handling that displays some more relevant info. For example:

no implicit conversion of String into Integer

Building all distributions.
Error: Could not generate docs:
TypeError: no implicit conversion of String into Integer at
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_entity.rb:14:in `[]'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_entity.rb:14:in `initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:16:in `new'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:16:in `block in initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:15:in `each'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:15:in `initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `new'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `topic_map'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:336:in `block in generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `each'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:17:in `call_generate'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:300:in `<top (required)>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `load'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `<main>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'.
Try --help for help.

Means that the YAML in the topic map is misformed and one of the entries can not be processed. For me the error was that I had removed a preceeding level of indentation but not removed the minus (-) at the beginning.

(WRONG)

---
- Name: Changelog
   Dir: changelog
   Topics:
     - Name: Changelog v1.5.5
        File: changelog-v1.5.5

(Correct)

---
Name: Changelog
Dir: changelog
Topics:
  - Name: Changelog v1.5.5
    File: changelog-v1.5.5

Example 2:

NoMethodError: undefined method `[]' for nil:NilClass at

Building all distributions.
Error: Could not generate docs:
NoMethodError: undefined method `[]' for nil:NilClass at
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_entity.rb:14:in `initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:16:in `new'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:16:in `block in initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:15:in `each'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:15:in `initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `new'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `topic_map'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:336:in `block in generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `each'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:17:in `call_generate'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:300:in `<top (required)>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `load'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `<main>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'.
Try --help for help.

Means that you have a malformed line in the _topic_map.yml that can not be read.

For me I tried to have a placeholder comment instead of a new section.

(WRONG)

---
Name: Welcome Page
Dir: welcome
Topics:
  - Name: Welcome
    File: index
---
# HERE NEEDS TO BE MORE STUFF
---
Name: Migration
Dir: migration
Topics:
  - Name: HIRO Connect
    File: migration5.4-sp3-connect
---

(Correct)

---
Name: Welcome Page
Dir: welcome
Topics:
  - Name: Welcome
    File: index
---
Name: Migration
Dir: migration
Topics:
  - Name: HIRO Connect
    File: migration5.4-sp3-connect
---
Fryguy commented 7 years ago

So, this request is that if you have a topic file that is valid yaml, but malformed from asciibinder's perpective, you are expecting a better error message? If so, I agree...we probably should have a validation step immediately after parsing the yaml files.

r0ckarong commented 7 years ago

Psych::SyntaxError: (): did not find expected key while parsing a block mapping at line 76 column 3 at

Building all distributions.
Error: Could not generate docs:
Psych::SyntaxError: (<unknown>): did not find expected key while parsing a block mapping at line 76 column 3 at
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/psych-2.2.4/lib/psych.rb:380:in `parse'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/psych-2.2.4/lib/psych.rb:380:in `parse_stream'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/psych-2.2.4/lib/psych.rb:463:in `load_stream'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/topic_map.rb:13:in `initialize'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `new'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:114:in `topic_map'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:336:in `block in generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `each'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/lib/ascii_binder/engine.rb:308:in `generate_docs'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:17:in `call_generate'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/gems/ascii_binder-0.1.10.1/bin/asciibinder:300:in `<top (required)>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `load'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/asciibinder:23:in `<main>'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    /Users/mnapp/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'.

This means that one of the keys "below" the line displayed as erroneous is in the wrong indentation.

(WRONG)

Name: Something
Dir: something
Topics:
  - Name: Something Else
     File: something-else
  - Name: Something More
     File: something-more

Here something-more is not contained in the something directory but a level higher. Typically happens to me when rearranging structures.

(CORRECT)

Name: Something
Dir: something
Topics:
  - Name: Something Else
     File: something-else
- Name: Something More
   File: something-more
r0ckarong commented 7 years ago

@Fryguy Yes most of the errors you get when doing something bad are pure Ruby stacktraces that do not really bring your mistakes into context with AsciiBinder specific things. Especially when they are as striking as undefined method `[]' for nil:NilClass.

When you know that certain error messages like the examples here typically coincide with a specific false use of formatting then it would be very nice to have an error message pointing the user in the right direction.

If it said "Error foo occured, looks like you have a wrong indentation in your topic map somewhere around line x". That would give me a much better indication that I made a mistake there and not with any other changes to the template files, graphics, etc.

Fryguy commented 7 years ago

Anything that emits a Psych::Syntax error is a YAML syntax error, and it would be very difficult for us to figure out how to create an error message on how the author could "correct" it, however I agree that we should catch that error and at a minimum reply with something like

ERROR: .topic_map.yml has a YAML syntax error:

did not find expected key while parsing a block mapping at line 76 column 3

A valid YAML, but missing asciibinder specifics, should error with something like

ERROR: .topic_map.yml has invalid content:

Topic named "Changelog v1.5.5" is missing the File attribute