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

Give hint when user forgets to return Module from elaborate. #33

Closed
wants to merge 1 commit into from

Conversation

cr1901
Copy link
Contributor

@cr1901 cr1901 commented Jan 29, 2019

Multiple times, I have forgotten to return a Module from elaborate, and I've found the resulting error to be unhelpful (even though I realize what it means now). The following traceback is the alu.py example with line 23 commented out:

$ python3 alu.py generate
Traceback (most recent call last):
  File "alu.py", line 28, in <module>
    main(alu, ports=[alu.sel, alu.a, alu.b, alu.o, alu.co])
  File "C:\msys64\home\william\src\nmigen\nmigen\cli.py", line 76, in main
    main_runner(parser, parser.parse_args(), *args, **kwargs)
  File "C:\msys64\home\william\src\nmigen\nmigen\cli.py", line 46, in main_runner
    fragment = Fragment.get(design, platform)
  File "C:\msys64\home\william\src\nmigen\nmigen\hdl\ir.py", line 23, in get
    return Fragment.get(obj.elaborate(platform), platform)
  File "C:\msys64\home\william\src\nmigen\nmigen\hdl\ir.py", line 22, in get
    return Fragment.get(obj.get_fragment(platform), platform)
AttributeError: 'NoneType' object has no attribute 'get_fragment'

With this PR, I have added code to give a hint to users what the problem is likely to be. The traceback is changed to the following:

$ python3 alu.py generate
Traceback (most recent call last):
  File "alu.py", line 28, in <module>
    main(alu, ports=[alu.sel, alu.a, alu.b, alu.o, alu.co])
  File "C:\msys64\home\william\src\nmigen\nmigen\cli.py", line 76, in main
    main_runner(parser, parser.parse_args(), *args, **kwargs)
  File "C:\msys64\home\william\src\nmigen\nmigen\cli.py", line 46, in main_runner
    fragment = Fragment.get(design, platform)
  File "C:\msys64\home\william\src\nmigen\nmigen\hdl\ir.py", line 27, in get
    return Fragment.get(obj.elaborate(platform), platform)
  File "C:\msys64\home\william\src\nmigen\nmigen\hdl\ir.py", line 25, in get
    .format(type(obj).__name__))
AttributeError: 'NoneType' object has no attribute 'elaborate' or 'get_fragment'. Did you remember to return a Module object from each user-defined 'elaborate' or 'get_fragment' method?

@codecov
Copy link

codecov bot commented Jan 29, 2019

Codecov Report

Merging #33 into master will increase coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
+ Coverage   85.51%   85.52%   +<.01%     
==========================================
  Files          27       27              
  Lines        3915     3917       +2     
  Branches      764      765       +1     
==========================================
+ Hits         3348     3350       +2     
  Misses        478      478              
  Partials       89       89
Impacted Files Coverage Δ
nmigen/hdl/ir.py 96.93% <50%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43e4833...fd91e21. Read the comment docs.

@whitequark
Copy link
Contributor

Tests should never be in different commits, in general.

@whitequark
Copy link
Contributor

Implemented this in a slightly more idiomatic way in 8ee6bd8.

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

Successfully merging this pull request may close these issues.

None yet

2 participants