dukat icon indicating copy to clipboard operation
dukat copied to clipboard

Exception subclasses are generated as typealiases (for the wrong class) instead of proper subclasses

Open Vampire opened this issue 4 years ago • 4 comments

If you generate for @actions/cache, the generated cache.module_@actions_cache.kt contains

typealias ValidationError = Error
typealias ReserveCacheError = Error

This has three problems.

  1. JS Error is mapped to Throwable in Kotlin, so if at all, they should be aliases for Throwable
  2. The typealiases are no externals definition so Kotlin is not going to like them being in there, once the JsModule annotation was added
  3. 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

Vampire avatar Sep 04 '20 11:09 Vampire

These are the according TS declarations:

export declare class ValidationError extends Error {
    constructor(message: string);
}
export declare class ReserveCacheError extends Error {
    constructor(message: string);
}

Vampire avatar Sep 04 '20 11:09 Vampire

The fact that type aliases might end up in a @file:JsModule/ @file:JsQualifier-annotated file is a separate bug per se.

Schahen avatar Sep 04 '20 12:09 Schahen

Actually the file does not have a JsModule or JsQualifier annotation given by Dukat. I insert them after generation. Probably due to #240

Vampire avatar Sep 04 '20 12:09 Vampire

@actions/http-client 1.0.9 has the same problem now with typealias HttpClientError = Error.

Vampire avatar Nov 28 '20 01:11 Vampire