"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PollExhaustedError = exports.PollTimeoutError = exports.ConnectionError = exports.ServerError = exports.TimeoutError = exports.ConflictError = exports.GitInitError = exports.ConfigParseError = exports.ConfigValidationError = exports.ConfigWriteError = exports.ConfigReadError = exports.ConfigNotFoundError = exports.ConfigError = exports.UnsupportedLanguageError = exports.MissingProjectFileError = exports.MissingDependencyError = exports.ArtifactSizeError = exports.PackagingError = exports.AwsCredentialsError = exports.ValidationError = exports.ResourceNotFoundError = exports.DependencyCheckError = exports.AccessDeniedError = exports.AgentAlreadyExistsError = exports.NoProjectError = exports.BaseError = void 0;
exports.toError = toError;
const zod_js_1 = require("./zod.js");
class BaseError extends Error {
    errorSource;
    constructor(message, options) {
        super(message, options);
        this.name = this.constructor.name;
        this.errorSource = options.errorSource ?? options.defaultSource;
    }
}
exports.BaseError = BaseError;
/**
 * Converts an unknown thrown value to an Error instance.
 * Use in catch blocks to ensure the error field is always an Error object.
 */
function toError(err) {
    return err instanceof Error ? err : new Error(String(err));
}
// --- User errors ---
/**
 * Error indicating no agentcore project was found in the working directory.
 */
class NoProjectError extends BaseError {
    constructor(message, options) {
        super(message ?? 'No agentcore project found. Run "agentcore create" first.', {
            defaultSource: 'user',
            ...options,
        });
    }
}
exports.NoProjectError = NoProjectError;
/**
 * Error thrown when an agent with the same name already exists.
 */
class AgentAlreadyExistsError extends BaseError {
    constructor(agentName, options) {
        super(`An agent named "${agentName}" already exists in the schema.`, { defaultSource: 'user', ...options });
    }
}
exports.AgentAlreadyExistsError = AgentAlreadyExistsError;
/**
 * Error indicating an AWS permissions failure (AccessDenied / AccessDeniedException).
 */
class AccessDeniedError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.AccessDeniedError = AccessDeniedError;
/**
 * Error indicating missing system dependencies required for an operation.
 */
class DependencyCheckError extends BaseError {
    constructor(errors, options) {
        super(errors.join('\n'), { defaultSource: 'user', ...options });
    }
}
exports.DependencyCheckError = DependencyCheckError;
/**
 * Error indicating a referenced resource could not be found.
 */
class ResourceNotFoundError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.ResourceNotFoundError = ResourceNotFoundError;
/**
 * Error indicating invalid input or configuration values.
 */
class ValidationError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.ValidationError = ValidationError;
/**
 * Error thrown when AWS credentials are not configured or invalid.
 * Supports both a short message (for interactive mode) and detailed message (for CLI mode).
 */
class AwsCredentialsError extends BaseError {
    shortMessage;
    constructor(shortMessage, detailedMessage, options) {
        super(detailedMessage ?? shortMessage, { defaultSource: 'user', ...options });
        this.shortMessage = shortMessage;
    }
}
exports.AwsCredentialsError = AwsCredentialsError;
/**
 * Error indicating a packaging operation failed.
 */
class PackagingError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.PackagingError = PackagingError;
/**
 * Error indicating the packaged artifact exceeds the size limit.
 */
class ArtifactSizeError extends PackagingError {
    constructor(limitBytes, actualBytes, options) {
        super(`Packaged artifact exceeds ${limitBytes} bytes (actual: ${actualBytes}).`, options);
    }
}
exports.ArtifactSizeError = ArtifactSizeError;
/**
 * Error indicating a required binary or tool is not installed.
 */
class MissingDependencyError extends PackagingError {
    constructor(binary, installHint, options) {
        super(installHint ? `${binary} is required. ${installHint}` : `${binary} is required.`, options);
    }
}
exports.MissingDependencyError = MissingDependencyError;
/**
 * Error indicating a required project file is missing.
 */
class MissingProjectFileError extends PackagingError {
    constructor(filePath, options) {
        super(`Required project file not found: ${filePath}`, options);
    }
}
exports.MissingProjectFileError = MissingProjectFileError;
/**
 * Error indicating the project language is not supported for packaging.
 */
class UnsupportedLanguageError extends PackagingError {
    constructor(language, options) {
        super(`${language} packaging is not supported yet.`, options);
    }
}
exports.UnsupportedLanguageError = UnsupportedLanguageError;
// --- Config errors (user) ---
/**
 * Base class for all config-related errors.
 */
class ConfigError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.ConfigError = ConfigError;
/**
 * Thrown when a config file doesn't exist.
 */
class ConfigNotFoundError extends ConfigError {
    filePath;
    fileType;
    constructor(filePath, fileType) {
        super(`${fileType} config file not found at: ${filePath}`);
        this.filePath = filePath;
        this.fileType = fileType;
    }
}
exports.ConfigNotFoundError = ConfigNotFoundError;
/**
 * Thrown when a config file can't be read.
 */
class ConfigReadError extends ConfigError {
    filePath;
    cause;
    constructor(filePath, cause) {
        const message = cause instanceof Error ? cause.message : String(cause);
        super(`Failed to read config file at ${filePath}: ${message}`);
        this.filePath = filePath;
        this.cause = cause;
    }
}
exports.ConfigReadError = ConfigReadError;
/**
 * Thrown when a config file can't be written.
 */
class ConfigWriteError extends ConfigError {
    filePath;
    cause;
    constructor(filePath, cause) {
        const message = cause instanceof Error ? cause.message : String(cause);
        super(`Failed to write config file at ${filePath}: ${message}`);
        this.filePath = filePath;
        this.cause = cause;
    }
}
exports.ConfigWriteError = ConfigWriteError;
/**
 * Thrown when config validation fails.
 */
class ConfigValidationError extends ConfigError {
    filePath;
    fileType;
    zodError;
    constructor(filePath, fileType, zodError) {
        super(`${filePath}:\n${(0, zod_js_1.formatZodErrors)(zodError.issues)}`);
        this.filePath = filePath;
        this.fileType = fileType;
        this.zodError = zodError;
    }
}
exports.ConfigValidationError = ConfigValidationError;
/**
 * Thrown when JSON parsing fails.
 */
class ConfigParseError extends ConfigError {
    filePath;
    cause;
    constructor(filePath, cause) {
        const message = cause instanceof Error ? cause.message : String(cause);
        super(`Failed to parse JSON in config file at ${filePath}: ${message}`);
        this.filePath = filePath;
        this.cause = cause;
    }
}
exports.ConfigParseError = ConfigParseError;
// --- Client errors ---
/**
 * Error indicating git repository initialization failed.
 */
class GitInitError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'client', ...options });
    }
}
exports.GitInitError = GitInitError;
// --- Service errors ---
/**
 * Error indicating a resource conflict (e.g., already exists).
 */
class ConflictError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'user', ...options });
    }
}
exports.ConflictError = ConflictError;
/**
 * Error indicating an operation timed out or exceeded retry limits.
 */
class TimeoutError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'service', ...options });
    }
}
exports.TimeoutError = TimeoutError;
/**
 * Error thrown when the dev server returns a non-OK HTTP response.
 */
class ServerError extends BaseError {
    statusCode;
    constructor(statusCode, body, options) {
        super(body || `Server returned ${statusCode}`, { defaultSource: 'client', ...options });
        this.statusCode = statusCode;
    }
}
exports.ServerError = ServerError;
/**
 * Error thrown when the connection to the dev server fails.
 */
class ConnectionError extends BaseError {
    constructor(message, options) {
        super(message, { defaultSource: 'client', ...options });
    }
}
exports.ConnectionError = ConnectionError;
/**
 * Error indicating polling timed out.
 */
class PollTimeoutError extends BaseError {
    constructor(timeoutMs, options) {
        super(`Polling timed out after ${timeoutMs}ms`, { defaultSource: 'service', ...options });
    }
}
exports.PollTimeoutError = PollTimeoutError;
/**
 * Error indicating polling exhausted all retry attempts.
 */
class PollExhaustedError extends BaseError {
    constructor(maxAttempts, options) {
        super(`Polling exhausted after ${maxAttempts} attempts`, { defaultSource: 'service', ...options });
    }
}
exports.PollExhaustedError = PollExhaustedError;
//# sourceMappingURL=types.js.map