import { formatUserError , UserError } from "@adpt/utils" ; import { CustomError } from "ts-custom-error" ; import { inspect } from "util" ; export { InternalError } from "@adpt/utils" ; export class BuildNotImplemented extends CustomError { public constructor ( message ? ) { super ( message ) ; } } export class ElementNotInDom extends CustomError { public constructor ( message ? ) { super ( message ) ; } } export class ProjectBuildError extends UserError { constructor ( public domXml ) { super ( `Error building Adapt project` ) ; } } export class ProjectCompileError extends CustomError { constructor ( msg ) { super ( `Error compiling Adapt project\n${ msg }` ) ; } } export class ProjectRunError extends CustomError { projectError : Error ; projectStack : string ; fullStack : string ; constructor ( projectError , projectStack , fullStack ) { let msg = `Error executing Adapt project: ` ; msg += projectError . message || projectError . name ; super ( msg ) ; this . projectError = projectError ; this . projectStack = projectStack ; this . fullStack = fullStack ; } } export function formatProjectError ( e ) { if ( ! ( e instanceof ProjectRunError ) ) return formatUserError ( e ) ; const peMsg = e . projectError . message ; const lines = e . projectStack . split ( "\n" ) ; if ( e . message . includes ( peMsg ) && lines [ 0 ] . includes ( peMsg ) ) { lines . shift ( ) ; } return `${ e . message }:\n${ lines . join ( "\n" ) }` ; } export class ThrewNonError extends CustomError { constructor ( public thrown ) { super ( `An exception was thrown with a non-Error object: '${ inspect ( thrown ) }'` ) ; } } export function isError ( val ) { return ( ( val != null ) && ( typeof val . message === "string" ) && ( typeof val . name === "string" ) && ( val . stack === undefined || typeof val . stack === "string" ) ) ; } export class DeployStepIDNotFound extends CustomError { constructor ( opID , stepNum ) { super ( `Deployment step ID ${ opID }.${ stepNum } not found` ) ; } } export class DeploymentNotActive extends CustomError { constructor ( deployID ) { super ( `Deployment ${ deployID } is not yet active. ` + `(DeployOpID 0 has not been deployed)` ) ; } } export class DeploymentOpIDNotActive extends CustomError { constructor ( deployID , opID ) { super ( `Deployment operation ID ${ opID } for Deployment ${ deployID } ` + `is not yet active. (Step 0 has not been deployed)` ) ; } }