mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-07 14:28:09 +03:00
fix: enforce prototypes in converter-failures
Typescript sometimes decides to "compile out" prototype chains like this we have to *enforce* that these classes have the right inheritance, because we do instanceof checks to determine what kind of error was thrown. We could switch to a tagged union approach, but this seems more stable.
This commit is contained in:
@@ -9,6 +9,8 @@ export class ConverterFailure extends Error {
|
||||
constructor(message: string) {
|
||||
super();
|
||||
this.message = message;
|
||||
|
||||
Object.setPrototypeOf(this, ConverterFailure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +19,18 @@ export class ConverterFailure extends Error {
|
||||
* support it. This is not an error, but is not a success either.
|
||||
* An example scenario would be something like a 5KEY score being imported from SSS.
|
||||
*/
|
||||
export class SkipScoreFailure extends ConverterFailure {}
|
||||
export class SkipScoreFailure extends ConverterFailure {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
|
||||
// @hack
|
||||
// Typescript sometimes decides to "compile out" prototype chains like this
|
||||
// we have to *enforce* that these classes have the right inheritance,
|
||||
// because we do instanceof checks to determine what kind of error was
|
||||
// thrown. We could switch to a tagged union approach, but this seems more stable.
|
||||
Object.setPrototypeOf(this, SkipScoreFailure);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* KTDataNotFoundError - We could not find the song or chart this score
|
||||
@@ -40,6 +53,8 @@ export class KTDataNotFoundFailure<T extends ImportTypes> extends ConverterFailu
|
||||
this.importType = importType;
|
||||
this.data = data;
|
||||
this.converterContext = context;
|
||||
|
||||
Object.setPrototypeOf(this, KTDataNotFoundFailure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +62,22 @@ export class KTDataNotFoundFailure<T extends ImportTypes> extends ConverterFailu
|
||||
* InvalidScoreError - This score provided invalid data that we
|
||||
* can not accept.
|
||||
*/
|
||||
export class InvalidScoreFailure extends ConverterFailure {}
|
||||
export class InvalidScoreFailure extends ConverterFailure {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
|
||||
Object.setPrototypeOf(this, InvalidScoreFailure);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* KTInternalFailure - An unexpected, internal error has occured,
|
||||
* and the score could not be processed.
|
||||
*/
|
||||
export class InternalFailure extends ConverterFailure {}
|
||||
export class InternalFailure extends ConverterFailure {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
|
||||
Object.setPrototypeOf(this, InternalFailure);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user