dukat
dukat copied to clipboard
Exception subclasses are generated as typealiases (for the wrong class) instead of proper subclasses
If you generate for @actions/cache
, the generated cache.module_@actions_cache.kt
contains
typealias ValidationError = Error
typealias ReserveCacheError = Error
This has three problems.
- JS
Error
is mapped toThrowable
in Kotlin, so if at all, they should be aliases forThrowable
- The typealiases are no externals definition so Kotlin is not going to like them being in there, once the
JsModule
annotation was added - The fact that they are actually typealiases instead of proper subclasses. This makes it impossible to have different catch clauses like this: https://github.com/Vampire/setup-wsl/blob/master/src/main/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt#L140-L157, as all exceptions are mapped to the same class then and it will not work properly. If you instead replace the typealiases with this, you can properly use mutliple catch clauses:
external class ValidationError : Throwable
external class ReserveCacheError : Throwable
These are the according TS declarations:
export declare class ValidationError extends Error {
constructor(message: string);
}
export declare class ReserveCacheError extends Error {
constructor(message: string);
}
The fact that type aliases might end up in a @file:JsModule
/ @file:JsQualifier
-annotated file is a separate bug per se.
Actually the file does not have a JsModule
or JsQualifier
annotation given by Dukat.
I insert them after generation.
Probably due to #240
@actions/http-client
1.0.9 has the same problem now with typealias HttpClientError = Error
.