PolicyEngine / openfisca-us-data

Python package to standardise loading input datasets to OpenFisca-US.
4 stars 3 forks source link

Throw informative error message when running `cps generate` before `raw_cps generate` #27

Closed MaxGhenis closed 2 years ago

MaxGhenis commented 2 years ago

e.g. here's what happens when trying to generate the CPS for a year prior to generating the raw CPS:

(base) mghenis@penguin:~/PolicyEngine/openfisca-us-data$ openfisca-us-data cps generate 2018                                                                    
Downloaded ASEC: 100%|████████████████████| 13.5k/13.5k [00:00<00:00, 175kiB/s]
Traceback (most recent call last):
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/datasets/cps/raw_cps.py", line 40, in generate                                           
    zipfile = ZipFile(file)
  File "/home/mghenis/anaconda3/lib/python3.8/zipfile.py", line 1269, in __init__                                                                               
    self._RealGetContents()
  File "/home/mghenis/anaconda3/lib/python3.8/zipfile.py", line 1336, in _RealGetContents                                                                       
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/cli.py", line 17, in main                                                                
    return getattr(datasets[args.dataset], args.action)(*args.args)
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/utils.py", line 94, in new_generate_func                                                 
    return generate_func(year, *args)
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/datasets/cps/cps.py", line 22, in generate                                               
    RawCPS.generate(year)
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/utils.py", line 94, in new_generate_func                                                 
    return generate_func(year, *args)
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/datasets/cps/raw_cps.py", line 51, in generate                                           
    f"Attempted to extract and save the CSV files, but encountered an error: {e.with_traceback()}"                                                              
TypeError: with_traceback() takes exactly one argument (0 given)

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/mghenis/anaconda3/bin/openfisca-us-data", line 33, in <module>
    sys.exit(load_entry_point('openfisca-us-data', 'console_scripts', 'openfisca-us-data')())                                                                   
  File "/home/mghenis/PolicyEngine/openfisca-us-data/openfisca_us_data/cli.py", line 19, in main                                                                
    print(f"Encountered an error: {e.with_traceback()}")