"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_constants_sentinels = require('../constants/sentinels.js');
const require_errors_predicates = require('./predicates.js');
let src_external_pony_cause = require("../external/pony-cause");

//#region src/errors/message.ts
/**
* @file Human-readable error-message extractor. `errorMessage` walks the
*   `cause` chain via pony-cause's `messageWithCauses` for Errors and falls
*   back to the shared `UNKNOWN_ERROR` sentinel for everything else.
*   `messageWithCauses` and `UNKNOWN_ERROR` are re-exported for callers that
*   need them directly.
*/
/**
* Extract a human-readable message from any caught value.
*
* Walks the `cause` chain for Errors (via {@link messageWithCauses}); coerces
* primitives and objects to string; returns {@link UNKNOWN_ERROR} for `null`,
* `undefined`, empty strings, `[object Object]`, or Errors with no message.
*
* @example
*   try {
*     await readConfig(path)
*   } catch (e) {
*     throw new ErrorCtor(`Failed to read ${path}: ${errorMessage(e)}`, {
*       cause: e,
*     })
*   }
*/
function errorMessage(value) {
	if (require_errors_predicates.isError(value)) return (0, src_external_pony_cause.messageWithCauses)(value) || "Unknown error";
	if (value === null || value === void 0) return require_constants_sentinels.UNKNOWN_ERROR;
	const s = String(value);
	if (s === "" || s === "[object Object]") return require_constants_sentinels.UNKNOWN_ERROR;
	return s;
}

//#endregion
exports.UNKNOWN_ERROR = require_constants_sentinels.UNKNOWN_ERROR;
exports.errorMessage = errorMessage;
exports.messageWithCauses = src_external_pony_cause.messageWithCauses;