Skip to content

Commit

Permalink
refactor(backend): avoid writing potentially very long log messages
Browse files Browse the repository at this point in the history
Sequences are potentially very long and thus those error messages are potentially very long.
  • Loading branch information
fengelniederhammer committed Aug 26, 2024
1 parent 1b99b59 commit 6373746
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class ProcessedSequenceEntryValidator(private val schema: Schema, private val re
if (invalidSymbols.isNotEmpty()) {
throw ProcessingValidationException(
"The sequence of segment '$segmentName' in '$sequenceGrouping' " +
"contains invalid symbols: $invalidSymbols.",
"contains invalid symbols: ${invalidSymbols.displayFirstCoupleSymbols()}.",
)
}
}
Expand All @@ -318,19 +318,19 @@ class ProcessedSequenceEntryValidator(private val schema: Schema, private val re
if (invalidSymbols.isNotEmpty()) {
throw ProcessingValidationException(
"The insertion $insertion of segment '${sequence.key}' in 'nucleotideInsertions' " +
"contains invalid symbols: $invalidSymbols.",
"contains invalid symbols: ${invalidSymbols.displayFirstCoupleSymbols()}.",
)
}
}
}
}

private inline fun <reified ValidSymbols> String.getInvalidSymbols()
where ValidSymbols : Enum<ValidSymbols>, ValidSymbols : Symbol =
where ValidSymbols : Enum<ValidSymbols>, ValidSymbols : Symbol =
this.filter { !it.isValidSymbol<ValidSymbols>() }.toList()

private inline fun <reified ValidSymbols> Char.isValidSymbol()
where ValidSymbols : Enum<ValidSymbols>, ValidSymbols : Symbol =
where ValidSymbols : Enum<ValidSymbols>, ValidSymbols : Symbol =
enumValues<ValidSymbols>().any { it.symbol == this }

private fun validateAminoAcidSequences(processedData: ProcessedData<GeneticSequence>) {
Expand Down Expand Up @@ -380,7 +380,7 @@ class ProcessedSequenceEntryValidator(private val schema: Schema, private val re
if (invalidSymbols.isNotEmpty()) {
throw ProcessingValidationException(
"The gene '$gene' in 'alignedAminoAcidSequences' " +
"contains invalid symbols: $invalidSymbols.",
"contains invalid symbols: ${invalidSymbols.displayFirstCoupleSymbols()}.",
)
}
}
Expand All @@ -393,7 +393,7 @@ class ProcessedSequenceEntryValidator(private val schema: Schema, private val re
if (invalidSymbols.isNotEmpty()) {
throw ProcessingValidationException(
"An insertion of gene '${sequence.key}' in 'aminoAcidInsertions' " +
"contains invalid symbols: $invalidSymbols.",
"contains invalid symbols: ${invalidSymbols.displayFirstCoupleSymbols()}.",
)
}
}
Expand Down Expand Up @@ -425,3 +425,12 @@ class ProcessedSequenceEntryValidator(private val schema: Schema, private val re
)
}
}

private fun List<Char>.displayFirstCoupleSymbols() = this.map { it.toString() }
.let {
when {
it.size > 10 -> it.take(10) + "..."
else -> it
}
}
.joinToString(separator = ", ", prefix = "[", postfix = "]")

0 comments on commit 6373746

Please sign in to comment.