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

tardis/plasma/standard_plasmas.py: old database files warning #799

Merged
merged 7 commits into from
Nov 4, 2017

Conversation

laudb
Copy link
Contributor

@laudb laudb commented Oct 15, 2017

displays a warning when using old atomic database files

displays a warning when using old atomic database files
try:
atom_data = atomic.AtomData.from_hdf(atom_data_fname)
except TypeError:
logger.warn('Use new configuration for the atomic database')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laudb you need to reraise the exception because it doesn't work with the old dataset. In this reraised exception you should suggest that the error likely occured due to the use of an old-format atomic database. Then also point to where to download a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkerzendorf okay, I think I understand what you mean, will make changes to the exception and modify the logged message

displays warning when using old version of database files - edited exception and logged message
@wkerzendorf
Copy link
Member

retainer the exception and put the error message in the exception not in the logger

@wkerzendorf
Copy link
Member

Sorry reraise

displays warning when using old version of database files - raised exception with error message
@laudb
Copy link
Contributor Author

laudb commented Oct 23, 2017

@wkerzendorf grateful for the pointers. I made the necessary change, will it suffice?


try:
atom_data = atomic.AtomData.from_hdf(atom_data_fname)
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should never have blanket exceptions. Always catch specific exceptions - you want your code to fail if it hits an unknown problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkerzendorf okay, noted. I've made this change in the next update.

displays warning when using old version of database files - use specific exception
@laudb
Copy link
Contributor Author

laudb commented Oct 27, 2017

@wkerzendorf I've been looking at this some more, and I'm also considering this possibility:

try: 
    atom_data = atomic.AtomData.from_hdf(atom_data_fname) # read data from 

#  the error due to old file shows as TypeError, hence TypeError exception
except TypeError: 
   
    # suggests possible problem and solution, "raise TypeError ('message')" hides cause of error   `
    print("Error might be from the use of an old-format of the atomic database,\n please see '+ \
            'https://github.com/tardis-sn/tardis-refdata/tree/master/atom_data for the most recent version.")

    # still shows what caused the error 
    raise 

@wkerzendorf
Copy link
Member

@laudb you can catch the error and access the message. So catch the error - display the message and add that this error might be due to the wrong dataset. I'm being very particular there because I want you to understand the error handling better. I know it's difficult and you're doing well - push on 😉

displays warning when using old version of database files - print error and helpful message
raise ValueError('Error might be from the use of an old-format of the atomic database,\n please see '+ \
'https://github.com/tardis-sn/tardis-refdata/tree/master/atom_data for the most recent version.')
except TypeError as e:
print (e, 'Error might be from the use of an old-format of the atomic database, \n' +\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the plus. every string in parenthesis is automatically concatenated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, noted, thanks!

displays warning when using old version of database files - remove unneeded plus from helpful message

try:
atom_data = atomic.AtomData.from_hdf(atom_data_fname)
except TypeError as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and no \ 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll have another go.. so catch the error, access the message and display it with the helpful suggestion or possible reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh..now I see

displays warning when using old version of database files - remove unneeded \ from helpful message
@wkerzendorf
Copy link
Member

@tardis-sn/tardis-core please have a look at this - I'm fine with merging

Copy link
Contributor

@ssim ssim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me too!

@laudb
Copy link
Contributor Author

laudb commented Nov 4, 2017

awesome!

@wkerzendorf wkerzendorf merged commit e67d83f into tardis-sn:master Nov 4, 2017
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.

3 participants