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

AttributeError: 'NoneType' object has no attribute 'get' #90

Open
Pyrrha opened this issue Nov 7, 2023 · 2 comments
Open

AttributeError: 'NoneType' object has no attribute 'get' #90

Pyrrha opened this issue Nov 7, 2023 · 2 comments

Comments

@Pyrrha
Copy link

Pyrrha commented Nov 7, 2023

Hello,

For my first use, after successfully fighting with dependencies, I ran into this error:

Traceback (most recent call last):
  File "/Users/x/venv/bin/code2flow", line 8, in <module>
    sys.exit(main())
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/engine.py", line 874, in main
    level=level,
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/engine.py", line 737, in code2flow
    skip_parse_errors, lang_params)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/engine.py", line 478, in map_it
    file_group = make_file_group(file_ast_tree, source, extension)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/engine.py", line 359, in make_file_group
    file_group.add_node(language.make_root_node(body_trees, parent=file_group), is_root=True)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 372, in make_root_node
    calls = make_calls(lines)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 105, in make_calls
    for element in walk(body):
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 35, in walk
    ret += walk(el)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 42, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 35, in walk
    ret += walk(el)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 40, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 40, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 42, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 35, in walk
    ret += walk(el)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 40, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 42, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 35, in walk
    ret += walk(el)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 42, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 35, in walk
    ret += walk(el)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 40, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 42, in walk
    ret += walk(v)
  File "/Users/x/venv/lib/python3.7/site-packages/code2flow/javascript.py", line 33, in walk
    if el.get('type'):
AttributeError: 'NoneType' object has no attribute 'get'

Steps to reproduce:

  • Install needed dependencies
  • Run code2flow *.js workflows/*.js bin/*.js --output out.dot in corresponding arborescence root

I used a collection of JS files, separated into multiple folders.
As the code stated, I suspect a bug inside the tool itself. Is there anything to fix this?

Thanks

@bbailleux
Copy link

Hello @Pyrrha

I've just faced the same problem and the only help found so far is your own unanswered question!

I have had a look to the …/code2flow/javascript.py file, and it appears that the related line (n 33) makes a test that may not be protected enough.

I just tried to replace it as follow:

--- /[…]/lib/python3.10/site-packages/code2flow/javascript.py.original	2024-03-05 14:49:51.895071571 +0100
+++ /[…]/lib/python3.10/site-packages/code2flow/javascript.py	2024-03-05 14:42:55.807765683 +0100
@@ -31,5 +31,5 @@ def walk(tree):
     if type(tree) == list:
         for el in tree:
-            if el.get('type'):
+            if el and el.get('type'):
                 ret.append(el)
                 ret += walk(el)

(just adds a test to check if el could be equal to None…)

By the way, that fixed the problem for me in some cases, but code2flow still crashes in some other cases.

Hope this helps.

@Pyrrha
Copy link
Author

Pyrrha commented Mar 5, 2024

Hello @bbailleux,

Thanks for your help, I did not use this tool for my need since I opened this issue. However I'll keep your answer if I use this tool in the future 😄

You maybe should open a PR to share your fix for the others?

Thanks!

@Pyrrha Pyrrha closed this as completed Mar 5, 2024
@Pyrrha Pyrrha reopened this Mar 5, 2024
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

No branches or pull requests

2 participants