const { SetCtor: _p_SetCtor } = require('../primordials/map-set.js')
"use strict";
/**
 * Bundled from pony-cause
 * This is a zero-dependency bundle created by rolldown.
 */
'use strict';

//#region \0rolldown/runtime.js
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
	value,
	configurable: true
});
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);

//#endregion

//#region node_modules/.pnpm/pony-cause@2.1.11_patch_hash=39b2eb2567818b7c60126d03e252dbbabd8738082fca850582300d45b0a8cfb8/node_modules/pony-cause/lib/error-with-cause.js
var require_error_with_cause = /* @__PURE__ */ __commonJSMin(((exports, module) => {
	/** @template [T=undefined] */
	var ErrorWithCause = class ErrorWithCause extends Error {
		/**
		* @param {string} message
		* @param {{ cause?: T }} options
		*/
		constructor(message, { cause } = {}) {
			super(message);
			/** @type {string} */
			this.name = ErrorWithCause.name;
			if (cause)
 /** @type {T} */
			this.cause = cause;
			/** @type {string} */
			this.message = message;
		}
	};
	module.exports = { ErrorWithCause };
}));

//#endregion
//#region node_modules/.pnpm/pony-cause@2.1.11_patch_hash=39b2eb2567818b7c60126d03e252dbbabd8738082fca850582300d45b0a8cfb8/node_modules/pony-cause/lib/helpers.js
var require_helpers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
	const isError = typeof Error.isError === "function" ? Error.isError : (v) => v !== null && typeof v === "object" && Object.prototype.toString.call(v) === "[object Error]";
	/**
	* @template {Error} T
	* @param {unknown} err
	* @param {new(...args: any[]) => T} reference
	* @returns {T|undefined}
	*/
	const findCauseByReference = (err, reference) => {
		if (!err || !reference) return;
		if (!isError(err)) return;
		if (!(reference.prototype instanceof Error) && reference !== Error) return;
		/**
		* Ensures we don't go circular
		*
		* @type {Set<Error>}
		*/
		const seen = /* @__PURE__ */ new _p_SetCtor();
		/** @type {Error|undefined} */
		let currentErr = err;
		while (currentErr && !seen.has(currentErr)) {
			seen.add(currentErr);
			if (currentErr instanceof reference) return currentErr;
			currentErr = getErrorCause(currentErr);
		}
	};
	/**
	* @param {Error|{ cause?: unknown|(()=>err)}} err
	* @returns {Error|undefined}
	*/
	const getErrorCause = (err) => {
		if (!err || typeof err !== "object" || !("cause" in err)) return;
		if (typeof err.cause === "function") {
			const causeResult = err.cause();
			return isError(causeResult) ? causeResult : void 0;
		} else return isError(err.cause) ? err.cause : void 0;
	};
	/**
	* Internal method that keeps a track of which error we have already added, to avoid circular recursion
	*
	* @private
	* @param {Error} err
	* @param {Set<Error>} seen
	* @returns {string}
	*/
	const _stackWithCauses = (err, seen) => {
		if (!isError(err)) return "";
		const stack = err.stack || "";
		if (seen.has(err)) return stack + "\ncauses have become circular...";
		const cause = getErrorCause(err);
		if (cause) {
			seen.add(err);
			return stack + "\ncaused by: " + _stackWithCauses(cause, seen);
		} else return stack;
	};
	/**
	* @param {Error} err
	* @returns {string}
	*/
	const stackWithCauses = (err) => _stackWithCauses(err, /* @__PURE__ */ new Set());
	/**
	* Internal method that keeps a track of which error we have already added, to avoid circular recursion
	*
	* @private
	* @param {Error} err
	* @param {Set<Error>} seen
	* @param {boolean} [skip]
	* @returns {string}
	*/
	const _messageWithCauses = (err, seen, skip) => {
		if (!isError(err)) return "";
		const message = skip ? "" : err.message || "";
		if (seen.has(err)) return message + ": ...";
		const cause = getErrorCause(err);
		if (cause) {
			seen.add(err);
			const skipIfVErrorStyleCause = "cause" in err && typeof err.cause === "function";
			return message + (skipIfVErrorStyleCause ? "" : ": ") + _messageWithCauses(cause, seen, skipIfVErrorStyleCause);
		} else return message;
	};
	/**
	* @param {Error} err
	* @returns {string}
	*/
	const messageWithCauses = (err) => _messageWithCauses(err, /* @__PURE__ */ new Set());
	module.exports = {
		findCauseByReference,
		getErrorCause,
		stackWithCauses,
		messageWithCauses
	};
}));

//#endregion
//#region node_modules/.pnpm/pony-cause@2.1.11_patch_hash=39b2eb2567818b7c60126d03e252dbbabd8738082fca850582300d45b0a8cfb8/node_modules/pony-cause/index.js
var require_pony_cause = /* @__PURE__ */ __commonJSMin(((exports, module) => {
	const { ErrorWithCause } = require_error_with_cause();
	const { findCauseByReference, getErrorCause, messageWithCauses, stackWithCauses } = require_helpers();
	module.exports = {
		ErrorWithCause,
		findCauseByReference,
		getErrorCause,
		stackWithCauses,
		messageWithCauses
	};
}));

//#endregion
//#region src/external/pony-cause.js
module.exports = require_pony_cause();

//#endregion