kformat icon indicating copy to clipboard operation
kformat copied to clipboard

Rows with different content causes table failure

Open rocketraman opened this issue 2 years ago • 0 comments

I have a case in which I have rows with different content. For example, some rows use a dash for a value if it is not applicable, while other rows may have a numeric value.

It seems like ktformat uses an "example row" to decide what formatting to apply to every row, but this then results in an exception like this:

java.lang.IllegalArgumentException: Can not format value '—' of type 'class java.lang.String 'using format spec '%-8d'

This seems like a common use case that it would be nice to handle elegantly. Perhaps one way to do it is to provide value converters as hints. If such a hint was provided, it would be used to transform the value for display rather than the example row.

The workaround is to ensure all values added to a row are consistent i.e. numeric values are converted to Strings in advance, so that the example row has consistent types with every other row.

rocketraman avatar Dec 16 '23 05:12 rocketraman