Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
Refs #10
  • Loading branch information
sverhoeven committed Jul 5, 2019
1 parent 79e7adc commit 8e2d456
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Script to create citation file formatted file (https://citation-file-format.gith

Current supported DOI types:

* Zenodo software from a GitHub release (https://guides.github.com/activities/citable-code/)
* Zenodo upload from a GitHub release (https://guides.github.com/activities/citable-code/)

Free software: Apache Software License 2.0

Expand Down
16 changes: 8 additions & 8 deletions doi2cff/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():
Current supported DOI types:
* Zenodo software from a GitHub release (https://guides.github.com/activities/citable-code/)
* Zenodo upload of a GitHub release (https://guides.github.com/activities/citable-code/)
"""
pass
Expand All @@ -39,7 +39,7 @@ def is_software_zenodo(zenodo_record):
def init(doi, cff_fn):
"""Generate CITATION.cff file based on a Zenodo DOI of a Github release.
* DOI, The Zenodo DOI url of a GitHub release
* DOI, The Digital Object Identifier (DOI) name of a Zenodo upload of a GitHub release
"""
template = '''# YAML 1.2
# Metadata for citation of this software according to the CFF format (https://citation-file-format.github.io/)
Expand All @@ -57,12 +57,12 @@ def init(doi, cff_fn):
'''

if not doi_is_from_zenodo(doi):
raise NotImplemented('Unable to process doi, converter not implemented')
raise click.UsageError('Unable to process DOI name, only accept DOI name which is a Zenodo upload')

zenodo_record = fetch_zenodo_by_doiurl(doi)

if not is_software_zenodo(zenodo_record):
raise NotImplemented('Unable to process doi, converter not implemented for Zenodo entries other than software')
raise click.UsageError('Unable to process DOI name, only accept DOI name which is a Zenodo upload of type software')

yaml = ruamel.yaml.YAML()
data = yaml.load(template)
Expand Down Expand Up @@ -101,7 +101,7 @@ def init(doi, cff_fn):
def update(doi, cff_fn):
"""Update CITATION.cff with doi, version and release date of a new release
* DOI, The Zenodo DOI url of a GitHub release
* DOI, The Digital Object Identifier (DOI) name of a Zenodo upload of a GitHub release
"""
update_version(doi, cff_fn)

Expand Down Expand Up @@ -129,9 +129,9 @@ def tagurl_of_zenodo(record):
if related_identifier['relation'] == 'isSupplementTo':

return related_identifier['identifier']
msg = 'Unable to process DOI, Zenodo record does not contain a related identifier ' \
msg = 'Unable to process DOI name, Zenodo upload does not contain a related identifier ' \
'with isSupplementTo relation, which is expected for DOI generated by GitHub'
raise KeyError(msg)
raise click.UsageError(msg)


def tagurl2repo(tagurl):
Expand Down Expand Up @@ -228,7 +228,7 @@ def authors_of_csl(record):
'family-names': name.last,
}
else:
raise NotImplemented('Do not understand author field: {}'.format(a))
raise click.UsageError('Unable to process DOI name, do not understand author field: {}'.format(a))
authors.append(author)
return authors

Expand Down

0 comments on commit 8e2d456

Please sign in to comment.