import { Duration } from "@restatedev/restate-sdk-core";

//#region src/types/errors.d.ts

declare class RestateError extends Error {
  readonly code: number;
  name: string;
  constructor(message: string, options?: {
    errorCode?: number;
    cause?: any;
  });
}
/**
 * Does not lead to Restate retries.
 *
 * Leads to an output message with a failure defined.
 */
declare class TerminalError extends RestateError {
  name: string;
  readonly metadata?: Record<string, string>;
  constructor(message: string, options?: {
    /**
     * Error code. This should be an HTTP status code, and in case the service was invoked from the ingress, this will be propagated back to the caller.
     */
    errorCode?: number;
    /**
     * Metadata key-value pairs to attach to the terminal error.
     * These will be recorded together with error message and code.
     *
     * **Note **: requires Restate 1.6+.
     */
    metadata?: Record<string, string>;
  });
}
/**
 * Returned by `RestatePromise.withTimeout` when the timeout is reached.
 */
declare class TimeoutError extends TerminalError {
  name: string;
  constructor();
}
/**
 * Returned when the invocation was cancelled.
 */
declare class CancelledError extends TerminalError {
  name: string;
  constructor();
}
interface RetryableErrorOptions {
  /**
   * In how long it should retry.
   */
  retryAfter?: Duration | number;
}
/**
 * Error that Restate will retry. By using this error type within a `ctx.run` closure,
 * you can dynamically provide the retry delay specified in {@link RetryableErrorOptions}.
 *
 * You can wrap another error using {@link from}.
 */
declare class RetryableError extends RestateError {
  name: string;
  readonly retryAfter?: Duration | number;
  constructor(message: string, options?: RetryableErrorOptions & {
    errorCode?: number;
    cause?: any;
  });
  /**
   * Create a `RetryableError` from the given cause.
   */
  static from(cause: any, options?: RetryableErrorOptions): RetryableError;
}
/**
 * Returns true if the error indicates the current attempt is ending without
 * a failure — e.g. the runtime suspended the invocation (waiting for
 * `ctx.sleep()` or `ctx.call()`), or the connection was dropped (kill).
 *
 * Use this in handler interceptor catch blocks to distinguish attempt-ending
 * signals from real errors (e.g. to avoid logging it as a failure or to set
 * a neutral span status).
 */
declare function isSuspendedError(e: unknown): boolean;
//#endregion
export { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError, isSuspendedError };
//# sourceMappingURL=errors.d.ts.map