"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionError=exports.AssumptionError=exports.UnscopedValidationError=exports.ValidationError=exports.Errors=void 0,exports.renderConstructRootPath=renderConstructRootPath;const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var fs=()=>{var tmp=require("fs");return fs=()=>tmp,tmp},runtime_info_1=()=>{var tmp=require("./private/runtime-info");return runtime_info_1=()=>tmp,tmp},stack_trace_1=()=>{var tmp=require("./stack-trace");return stack_trace_1=()=>tmp,tmp},cx_api_1=()=>{var tmp=require("../../cx-api");return cx_api_1=()=>tmp,tmp};const CONSTRUCT_ERROR_SYMBOL=Symbol.for("@aws-cdk/core.SynthesisError"),VALIDATION_ERROR_SYMBOL=Symbol.for("@aws-cdk/core.ValidationError"),ASSERTION_ERROR_SYMBOL=Symbol.for("@aws-cdk/assertions.AssertionError"),ASSEMBLY_ERROR_SYMBOL=Symbol.for("@aws-cdk/cx-api.CloudAssemblyError"),ASSUMPTION_ERROR_SYMBOL=Symbol.for("@aws-cdk/core.AssumptionError"),EXECUTION_ERROR_SYMBOL=Symbol.for("@aws-cdk/core.ExecutionError");class Errors{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.Errors",version:"2.256.1"};static isConstructError(x){return x!==null&&typeof x=="object"&&CONSTRUCT_ERROR_SYMBOL in x}static isValidationError(x){return Errors.isConstructError(x)&&VALIDATION_ERROR_SYMBOL in x}static isAssertionError(x){return Errors.isConstructError(x)&&ASSERTION_ERROR_SYMBOL in x}static isCloudAssemblyError(x){return x!==null&&typeof x=="object"&&ASSEMBLY_ERROR_SYMBOL in x}static isExecutionError(x){return x!==null&&typeof x=="object"&&EXECUTION_ERROR_SYMBOL in x}static isAssumptionError(x){return x!==null&&typeof x=="object"&&ASSUMPTION_ERROR_SYMBOL in x}}exports.Errors=Errors;class ConstructError extends Error{#time;#constructPath;#constructInfo;get time(){return this.#time}get level(){return"error"}get constructPath(){return this.#constructPath}get constructInfo(){return this.#constructInfo}constructor(msg,scope,name){super(msg);const ctr=this.constructor;if(Object.setPrototypeOf(this,ConstructError.prototype),Object.defineProperty(this,CONSTRUCT_ERROR_SYMBOL,{value:!0}),this.name=name??ctr.name,this.#time=new Date().toISOString(),this.#constructPath=scope?.node.path,scope)try{this.#constructInfo=(0,runtime_info_1().constructInfoFromConstruct)(scope)}catch{}this.stack=`\xAB${this.name}\xBB ${msg}
${(0,stack_trace_1().renderCallStackJustMyCode)((0,stack_trace_1().captureCallStack)(ctr)).join(`
`)}`,scope&&(this.stack+=`
Relates to construct:
${renderConstructRootPath(scope)}`),maybeWriteErrorCode(this.name)}}class ValidationError extends ConstructError{get type(){return"validation"}constructor(name,msg,scope){super(msg,scope,name),Object.setPrototypeOf(this,ValidationError.prototype),Object.defineProperty(this,VALIDATION_ERROR_SYMBOL,{value:!0})}}exports.ValidationError=ValidationError;class UnscopedValidationError extends ConstructError{get type(){return"validation"}constructor(name,msg){super(msg,void 0,name),Object.setPrototypeOf(this,UnscopedValidationError.prototype),Object.defineProperty(this,VALIDATION_ERROR_SYMBOL,{value:!0})}}exports.UnscopedValidationError=UnscopedValidationError;class AssumptionError extends ConstructError{get type(){return"assumption"}constructor(name,msg){super(msg,void 0,name),Object.setPrototypeOf(this,AssumptionError.prototype),Object.defineProperty(this,ASSUMPTION_ERROR_SYMBOL,{value:!0})}}exports.AssumptionError=AssumptionError;class ExecutionError extends ConstructError{get type(){return"exec"}constructor(name,msg){super(msg,void 0,name),Object.setPrototypeOf(this,ExecutionError.prototype),Object.defineProperty(this,EXECUTION_ERROR_SYMBOL,{value:!0})}}exports.ExecutionError=ExecutionError;function renderConstructRootPath(construct){const rootPath=[];let cur=construct;for(;cur!==void 0;)rootPath.push(cur),cur=cur.node.scope;rootPath.reverse();const ret=new Array;for(let i=0;i<rootPath.length;i++){const constructId=rootPath[i].node.id||"<.>";let suffix="";try{suffix=` (${(0,runtime_info_1().constructInfoFromConstruct)(rootPath[i])?.fqn})`}catch{}const branch=" \u2514\u2500 ",indent=i>0?" ".repeat(branch.length*(i-1))+branch:"";ret.push(`    ${indent}${constructId}${suffix}`)}return ret.join(`
`)}function maybeWriteErrorCode(errorCode){const file=process.env[cx_api_1().ERRORFILE_ENV];file&&fs().writeFileSync(file,errorCode,"utf-8")}
