Skip to content

Commit d440040

Browse files
authored
Improve error message for invalid contribution type in manifest contributors (#6593)
Signed-off-by: Ben Sherman <[email protected]>
1 parent 33943b5 commit d440040

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

modules/nextflow/src/main/groovy/nextflow/config/Manifest.groovy

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,11 @@ class Manifest implements ConfigScope {
170170
.map(opts -> new Contributor(opts))
171171
.toList()
172172
}
173-
catch( ClassCastException | IllegalArgumentException e ){
174-
throw new AbortOperationException("Invalid config option `manifest.contributors` -- should be a list of maps")
173+
catch( IllegalArgumentException e ){
174+
throw new AbortOperationException(e.message)
175+
}
176+
catch( ClassCastException e ){
177+
throw new AbortOperationException("Invalid setting for `manifest.contributors` config option -- should be a list of maps")
175178
}
176179
}
177180

@@ -208,17 +211,23 @@ class Manifest implements ConfigScope {
208211
affiliation = opts.affiliation as String
209212
email = opts.email as String
210213
github = opts.github as String
211-
contribution = parseContributionTypes(opts.contribution)
214+
contribution = parseContributionTypes(opts.contribution as List<String>)
212215
orcid = opts.orcid as String
213216
}
214217

215-
private List<ContributionType> parseContributionTypes(Object value) {
216-
if( value == null )
218+
private List<ContributionType> parseContributionTypes(List<String> values) {
219+
if( values == null )
217220
return []
218-
return (value as List<String>).stream()
219-
.map(c -> ContributionType.valueOf(c.toUpperCase()))
220-
.sorted()
221-
.toList()
221+
final result = new LinkedList<ContributionType>()
222+
for( final value : values ) {
223+
try {
224+
result.add(ContributionType.valueOf(value.toUpperCase()))
225+
}
226+
catch( IllegalArgumentException e ) {
227+
throw new IllegalArgumentException("Invalid contribution type '$value' in `manifest.contributors` config option")
228+
}
229+
}
230+
return result.toSorted()
222231
}
223232

224233
Map toMap() {

modules/nextflow/src/test/groovy/nextflow/config/ManifestTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ class ManifestTest extends Specification {
179179
])
180180
manifest.contributors
181181
then:
182-
thrown(AbortOperationException)
182+
def e = thrown(AbortOperationException)
183+
e.message.contains("Invalid contribution type 'owner' in `manifest.contributors` config option")
183184
}
184185

185186
}

0 commit comments

Comments
 (0)