-
-
Save sshine/1b4f0fdbb1660c08921faaff5d03fe79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type ClaErrorType = { | |
message: string; | |
extensions: ClaErrorTypeExtension[]; | |
locations: ClaErrorTypeLineColumn[]; | |
}; | |
export type ClaErrorTypeExtension = { | |
category: string; | |
}; | |
export type ClaErrorTypeLineColumn = { | |
line: number; | |
column: number; | |
}[]; | |
export class ClaError extends Error { | |
private reasons: ClaErrorType[]; | |
constructor(reasons: ClaErrorType[]) { | |
super(reasons.map(ClaError.formatClaError).join(', ')); | |
Object.setPrototypeOf(this, ClaError.prototype); | |
this.reasons = reasons; | |
} | |
public static formatLineCol = (position: ClaErrorTypeLineColumn): string => { | |
return `line ${position.line}, column ${position.column}`; | |
}; | |
public static formatClaError = (reason: ClaErrorType): string => { | |
const message = reason.message; | |
const locations = reason.locations.map(ClaError.formatLineCol).join(', '); | |
return `${message} on ${locations}`; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment