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

Uncaught yaml.composer.ComposerError with undefined alias with 'fmf show' #50

Closed
jakubkrysl opened this issue Oct 5, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@jakubkrysl
Copy link

$ fmf show
Traceback (most recent call last):
  File "/usr/bin/fmf", line 4, in <module>
    __import__('pkg_resources').run_script('fmf==0.5.1', 'fmf')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 654, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1441, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/fmf-0.5.1-py2.7.egg/EGG-INFO/scripts/fmf", line 35, in <module>

  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 194, in main
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 73, in __init__
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 131, in command_show
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 156, in show
  File "build/bdist.linux-x86_64/egg/fmf/base.py", line 80, in __init__
  File "build/bdist.linux-x86_64/egg/fmf/base.py", line 248, in grow
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/composer.py", line 129, in compose_mapping_node
    item_key = self.compose_node(node, None)
  File "/home/jkrysl/.local/lib/python2.7/site-packages/yaml/composer.py", line 69, in compose_node
    % anchor.encode('utf-8'), event.start_mark)
yaml.composer.ComposerError: found undefined alias 'test'
  in "/home/jkrysl/tests/fmf_test/main.fmf", line 1, column 1

$ cat main.fmf
*test: string

$ ls -la
total 16
drwxrwxr-x.  3 jkrysl jkrysl 4096 Oct  5 12:28 .
drwxrwxr-x. 20 jkrysl jkrysl 4096 Oct  5 10:49 ..
drwxrwxr-x.  2 jkrysl jkrysl 4096 Oct  5 10:49 .fmf
-rw-rw-r--.  1 jkrysl jkrysl   14 Oct  5 12:27 main.fmf

$ nano main.fmf
$ cat main.fmf
*test+: string

$ fmf show
 ERROR  Failed to parse '/home/jkrysl/tests/fmf_test/main.fmf'
while scanning an alias
  in "/home/jkrysl/tests/fmf_test/main.fmf", line 1, column 1
expected alphabetic or numeric character, but found '+'
  in "/home/jkrysl/tests/fmf_test/main.fmf", line 1, column 6
@jakubkrysl
Copy link
Author

Similar thing happens with undefined default:

$ cat main.fmf
&test+: string

$ fmf show
 ERROR  Failed to parse '/home/jkrysl/tests/fmf_test/main.fmf'
while scanning an anchor
  in "/home/jkrysl/tests/fmf_test/main.fmf", line 1, column 1
expected alphabetic or numeric character, but found '+'
  in "/home/jkrysl/tests/fmf_test/main.fmf", line 1, column 6

$ nano main.fmf
$ cat main.fmf
&test: string

$ fmf show
Traceback (most recent call last):
  File "/usr/bin/fmf", line 4, in <module>
    __import__('pkg_resources').run_script('fmf==0.5.1', 'fmf')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 654, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1441, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/fmf-0.5.1-py2.7.egg/EGG-INFO/scripts/fmf", line 35, in <module>

  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 194, in main
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 73, in __init__
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 131, in command_show
  File "build/bdist.linux-x86_64/egg/fmf/cli.py", line 156, in show
  File "build/bdist.linux-x86_64/egg/fmf/base.py", line 80, in __init__
  File "build/bdist.linux-x86_64/egg/fmf/base.py", line 256, in grow
  File "build/bdist.linux-x86_64/egg/fmf/base.py", line 161, in update
AttributeError: 'NoneType' object has no attribute 'startswith'

@psss psss self-assigned this Oct 8, 2018
@psss
Copy link
Collaborator

psss commented Oct 8, 2018

So, if I understand that correctly, we get traceback if the yaml file is not valid, right? When alias is properly defined, data are set as expected:

first: &alias value
second: *alias

gives:

/
first: value
second: value

and

name: &alias key
*alias: value

gives:

/
key: value
name: key

What do you propose? To have a shorter error message? The traceback gives some nice details about where the YAML syntax problem is.

@jakubkrysl
Copy link
Author

Yes, these situations are using invalid yaml file with undefined alias / default. You can get here either by forgetting to define those or as I did by not knowing of those and accidentally using the symbols */&. :)

We have basically 4 situations here:

  1. undefined clean alias *test: string
  2. undefined alias with append *test+: string
  3. undefined clean default &test: string
  4. undefined default with alias &test+: string

These produce:

  1. nice error with all the details
  2. some not really helpful error, shows parser error location but not the reason
  3. what seems to be pure fmf error, but the issue is in yaml parser
  4. same as 2.

Now the proposition here depends on the exact situation:

  1. I propose to catch and show to user instead of the 'ugly' trace
  2. / 4. I cannot try it now, but '+' seems to me like it should not be allowed with defaults/ aliases. Maybe we should tell this to user...
  3. Ideally the output should look like 1.

This whole issue is really corner case, so treat it with low priority :)

@psss psss added the bug Something isn't working label Oct 8, 2018
psss added a commit that referenced this issue Jun 14, 2019
@psss
Copy link
Collaborator

psss commented Jun 14, 2019

I've updated exception handling to cover all yaml errors and also covered the special None key case.

@psss psss closed this as completed in a02a24d Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants