Skip to content

Commit

Permalink
Merge pull request #1266 from rpetit3/rpetit3-print-choices
Browse files Browse the repository at this point in the history
display enum choices on error
  • Loading branch information
ewels authored Nov 16, 2021
2 parents 14abb1b + d63d233 commit ffab773
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions nf_core/pipeline-template/lib/NfcoreSchema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ class NfcoreSchema {

// Collect expected parameters from the schema
def expectedParams = []
def enums = [:]
for (group in schemaParams) {
for (p in group.value['properties']) {
expectedParams.push(p.key)
if (group.value['properties'][p.key].containsKey('enum')) {
enums[p.key] = group.value['properties'][p.key]['enum']
}
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ class NfcoreSchema {
println ''
log.error 'ERROR: Validation of pipeline parameters failed!'
JSONObject exceptionJSON = e.toJSON()
printExceptions(exceptionJSON, params_json, log)
printExceptions(exceptionJSON, params_json, log, enums)
println ''
has_error = true
}
Expand Down Expand Up @@ -329,7 +333,7 @@ class NfcoreSchema {
//
// Loop over nested exceptions and print the causingException
//
private static void printExceptions(ex_json, params_json, log) {
private static void printExceptions(ex_json, params_json, log, enums, limit=5) {
def causingExceptions = ex_json['causingExceptions']
if (causingExceptions.length() == 0) {
def m = ex_json['message'] =~ /required key \[([^\]]+)\] not found/
Expand All @@ -345,7 +349,16 @@ class NfcoreSchema {
else {
def param = ex_json['pointerToViolation'] - ~/^#\//
def param_val = params_json[param].toString()
log.error "* --${param}: ${ex_json['message']} (${param_val})"
if (enums.containsKey(param)) {
def error_msg = "* --${param}: '${param_val}' is not a valid choice (Available choices"
if (enums[param].size() > limit) {
log.error "${error_msg} (${limit} of ${enums[param].size()}): ${enums[param][0..limit-1].join(', ')}, ... )"
} else {
log.error "${error_msg}: ${enums[param].join(', ')})"
}
} else {
log.error "* --${param}: ${ex_json['message']} (${param_val})"
}
}
}
for (ex in causingExceptions) {
Expand Down

0 comments on commit ffab773

Please sign in to comment.