/**
 * Typed, loud errors for the lake accessor. A missing object, unreadable path, or bad
 * credential is **never** an empty result — it surfaces here (RUNTIME: fail-closed). Secrets
 * are never placed on an error: any SQL echoed in a message is redacted at the call site.
 */

/** The chosen resolution path for a read — reported on results and errors, never inferred. */
export type LakeSource = "s3" | "dev-local";

export interface LakeReadErrorOptions {
  cause?: unknown;
  /** The lake-relative object key the read was for. */
  rel?: string;
  /** Which path was attempted. */
  source?: LakeSource;
}

/** A read against the lake failed loudly (missing object, bad creds, engine error). */
export class LakeReadError extends Error {
  override readonly name = "LakeReadError";
  readonly rel: string | undefined;
  readonly source: LakeSource | undefined;

  constructor(message: string, options: LakeReadErrorOptions = {}) {
    super(message, options.cause === undefined ? undefined : { cause: options.cause });
    this.rel = options.rel;
    this.source = options.source;
  }
}

/** Lake configuration is missing or inconsistent (no local root and no usable S3 remote). */
export class LakeConfigError extends Error {
  override readonly name = "LakeConfigError";

  constructor(message: string, options: { cause?: unknown } = {}) {
    super(message, options.cause === undefined ? undefined : { cause: options.cause });
  }
}
