export class LightdashError extends Error {
    constructor({ message, name, statusCode, data }) {
        super(message);
        this.name = name;
        this.statusCode = statusCode;
        this.data = data;
    }
}
export class ForbiddenError extends LightdashError {
    constructor(message = "You don't have access to this resource or action", data = {}) {
        super({
            message,
            name: 'ForbiddenError',
            statusCode: 403,
            data,
        });
    }
}
export class GoogleNotConnectedError extends LightdashError {
    constructor(message = 'Google account not connected') {
        super({
            message,
            name: 'GoogleNotConnectedError',
            statusCode: 412,
            data: {},
        });
    }
}
export class DeactivatedAccountError extends LightdashError {
    constructor(message = 'Your account has been deactivated. Please contact your organization administrator.', data = {}) {
        super({
            message,
            name: 'DeactivatedAccountError',
            statusCode: 403,
            data,
        });
    }
}
export class AuthorizationError extends LightdashError {
    constructor(message = "You don't have authorization to perform this action", data = {}) {
        super({
            message,
            name: 'AuthorizationError',
            statusCode: 401,
            data,
        });
    }
}
export class ExpiredError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'ExpiredError',
            statusCode: 406,
            data: {},
        });
    }
}
export class ParameterError extends LightdashError {
    constructor(message = 'Incorrect parameters', data = {}) {
        super({
            message,
            name: 'ParameterError',
            statusCode: 400,
            data,
        });
    }
}
export class PayloadTooLargeError extends LightdashError {
    constructor(message = 'Request payload exceeds the maximum allowed size', data = {}) {
        super({
            message,
            name: 'PayloadTooLargeError',
            statusCode: 413,
            data,
        });
    }
}
export class NonCompiledModelError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'NonCompiledModelError',
            statusCode: 400,
            data,
        });
    }
}
export class MissingCatalogEntryError extends LightdashError {
    constructor(message, data) {
        super({
            message,
            name: 'MissingCatalogEntryError',
            statusCode: 400,
            data,
        });
    }
}
export class MissingWarehouseCredentialsError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'MissingWarehouseCredentialsError',
            statusCode: 400,
            data: {},
        });
    }
}
export class UnexpectedServerError extends LightdashError {
    constructor(message = 'Something went wrong.', data = {}) {
        super({
            message,
            name: 'UnexpectedServerError',
            statusCode: 500,
            data,
        });
    }
}
export class UnexpectedIndexError extends LightdashError {
    constructor(message = 'Invalid index in array.', data = {}) {
        super({
            message,
            name: 'UnexpectedIndexError',
            statusCode: 500,
            data,
        });
    }
}
export class UnexpectedGitError extends LightdashError {
    constructor(message = 'Unexpected error in Git adapter', data = {}) {
        super({
            message,
            name: 'UnexpectedGitError',
            statusCode: 400,
            data,
        });
    }
}
/**
 * Thrown when a Git write operation (create branch, commit, open/update PR) is
 * rejected because the credentials backing the connection lack write access —
 * e.g. GitHub returns 403 "Resource not accessible by integration". This is a
 * terminal setup problem (a personal access token without write scope, or a
 * GitHub App installation missing Contents/Pull-requests write), not a transient
 * failure, so callers should surface a one-time fix rather than retry.
 */
export class InsufficientGitPermissionsError extends LightdashError {
    constructor(message = 'The Git connection does not have write access to this repository', data = {}) {
        super({
            message,
            name: 'InsufficientGitPermissionsError',
            statusCode: 403,
            data,
        });
    }
}
export class UnexpectedDatabaseError extends LightdashError {
    constructor(message = 'Unexpected error in Lightdash database.', data = {}) {
        super({
            message,
            name: 'UnexpectedDatabaseError',
            statusCode: 500,
            data,
        });
    }
}
export class ParseError extends LightdashError {
    constructor(message = 'Error parsing dbt project and lightdash metadata', data = {}) {
        super({
            message,
            name: 'ParseError',
            statusCode: 400,
            data,
        });
    }
}
export class CompileError extends LightdashError {
    constructor(message = 'Error compiling sql from Lightdash configuration', data = {}) {
        super({
            message,
            name: 'CompileError',
            statusCode: 400,
            data,
        });
    }
}
export class FieldReferenceError extends LightdashError {
    constructor(message = 'Failed to reference field in dbt project', data = {}) {
        super({
            message,
            name: 'FieldReferenceError',
            statusCode: 400,
            data,
        });
    }
}
export class DbtError extends LightdashError {
    constructor(message = 'Dbt raised an error', logs = []) {
        super({
            message,
            name: 'DbtError',
            statusCode: 400,
            data: {},
        });
        this.logs = logs;
    }
}
export class NotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotFoundError',
            statusCode: 404,
            data: {},
        });
    }
}
export class NotSupportedError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotSupportedError',
            statusCode: 400,
            data: {},
        });
    }
}
export class InvalidUser extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'InvalidUser',
            statusCode: 404,
            data: {},
        });
    }
}
export class WarehouseConnectionError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'WarehouseConnectionError',
            statusCode: 400,
            data: {},
        });
    }
}
export class WarehouseQueryError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'WarehouseQueryError',
            statusCode: 400,
            data,
        });
    }
}
export class SmptError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'SmptError',
            statusCode: 500,
            data,
        });
    }
}
export class AlreadyProcessingError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AlreadyProcessingError',
            statusCode: 409,
            data: {},
        });
    }
}
export class AlreadyExistsError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AlreadyExistsError',
            statusCode: 409,
            data: {},
        });
    }
}
export class MissingConfigError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'MissingConfigError',
            statusCode: 422,
            data: {},
        });
    }
}
export class NotEnoughResults extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotEnoughResults',
            statusCode: 406,
            data: {},
        });
    }
}
export class PaginationError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'PaginationError',
            statusCode: 422,
            data: {},
        });
    }
}
export class SlackInstallationNotFoundError extends LightdashError {
    constructor(message = 'Could not find slack installation') {
        super({
            message,
            name: 'SlackInstallationNotFoundError',
            statusCode: 404,
            data: {},
        });
    }
}
export class SlackError extends LightdashError {
    constructor(message = 'Slack API error occurred', data = {}) {
        super({
            message,
            name: 'SlackError',
            statusCode: 400,
            data,
        });
    }
}
export class SlackFileUploadError extends LightdashError {
    constructor(message = 'Slack file upload failed', data = {}) {
        super({
            message,
            name: 'SlackFileUploadError',
            statusCode: 400,
            data,
        });
    }
}
export class MsTeamsError extends LightdashError {
    constructor(message = 'Microsoft Teams API error occurred', data = {}) {
        super({
            message,
            name: 'MsTeamsError',
            statusCode: 400,
            data,
        });
    }
}
export class GoogleChatError extends LightdashError {
    constructor(message = 'Google Chat API error occurred', data = {}) {
        super({
            message,
            name: 'GoogleChatError',
            statusCode: 400,
            data,
        });
    }
}
export class UnexpectedGoogleSheetsError extends LightdashError {
    constructor(message = 'Unexpected error in Google sheets client', data = {}) {
        super({
            message,
            name: 'UnexpectedGoogleSheetsError',
            statusCode: 400,
            data,
        });
    }
}
/* This specific error will be used in the frontend
to show a "Re-authenticate" button in the UI for Google Sheets scope issues
*/
export class GoogleSheetsScopeError extends LightdashError {
    constructor(message = 'Unable to validate Google Sheets file. Please re-authenticate with Google to grant the required permissions.', data = {}) {
        super({
            message,
            name: 'GoogleSheetsScopeError',
            statusCode: 403,
            data,
        });
    }
}
export class GoogleSheetsTransientError extends LightdashError {
    constructor(message = 'Unexpected error in Google Sheets API', data = {}) {
        super({
            message,
            name: 'GoogleSheetsTransientError',
            statusCode: 500,
            data,
        });
    }
}
export class GoogleSheetsQuotaError extends LightdashError {
    constructor(message = 'Google Sheets API quota exceeded. The sync will be retried automatically.', data = {}) {
        super({
            message,
            name: 'GoogleSheetsQuotaError',
            statusCode: 429,
            data,
        });
    }
}
export class NotImplementedError extends LightdashError {
    constructor(message = 'Not implemented') {
        super({
            message,
            name: 'NotImplemented',
            statusCode: 501,
            data: {},
        });
    }
}
export class DeprecatedRouteError extends LightdashError {
    constructor(message = 'Deprecated route called past its removal deadline', data = {}) {
        super({
            message,
            name: 'DeprecatedRouteError',
            statusCode: 410,
            data,
        });
    }
}
export const getErrorMessage = (e) => {
    if (e instanceof Error && e.message)
        return e.message;
    return `Unknown ${typeof e} error`;
};
export class ScreenshotError extends LightdashError {
    constructor(message = 'Error capturing screenshot', data = {}) {
        super({
            message,
            name: 'ScreenshotError',
            statusCode: 500,
            data,
        });
    }
}
export class SshTunnelError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'SshTunnelError',
            statusCode: 400,
            data: {},
        });
    }
}
export class ReadFileError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'ReadFileError',
            statusCode: 404,
            data,
        });
    }
}
export class S3Error extends LightdashError {
    constructor(message = 'Error occurred while interacting with S3', data = {}) {
        super({
            message,
            name: 'S3Error',
            statusCode: 500,
            data,
        });
    }
}
export class ResultsExpiredError extends LightdashError {
    constructor(message = 'Your results have expired. Please refresh the page or re-run the query.') {
        super({
            message,
            name: 'ResultsExpiredError',
            statusCode: 404,
            data: {},
        });
    }
}
export class ExpiredQueryError extends LightdashError {
    constructor(message = 'Your query expired while waiting in the queue. Please try again.', data = {}) {
        super({
            message,
            name: 'ExpiredQueryError',
            statusCode: 408,
            data,
        });
    }
}
export class TimeoutError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'TimeoutError',
            statusCode: 400,
            data: {},
        });
    }
}
export class AiDuplicateSlackPromptError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiDuplicateSlackPromptError',
            statusCode: 400,
            data: {},
        });
    }
}
export class AiSlackMappingNotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiSlackMappingNotFoundError',
            statusCode: 400,
            data: {},
        });
    }
}
export class AiAgentNotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiAgentNotFoundError',
            statusCode: 400,
            data: {},
        });
    }
}
export class AiAgentValidatorError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiAgentValidatorError',
            statusCode: 400,
            data: {},
        });
    }
}
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
export class SnowflakeTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'SnowflakeTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
export class DatabricksTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'DatabricksTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
export class BigqueryTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'BigqueryTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
export class CustomSqlQueryForbiddenError extends LightdashError {
    constructor(message = 'User cannot run queries with custom SQL dimensions') {
        super({
            message,
            name: 'CustomSqlQueryForbiddenError',
            statusCode: 403,
            data: {
                documentationUrl: `https://docs.lightdash.com/references/custom-fields#custom-sql`,
            },
        });
    }
}
export class OauthAuthenticationError extends LightdashError {
    constructor(message = 'OAuth authentication error', data = {}) {
        super({
            message,
            name: 'OauthAuthenticationError',
            statusCode: 401,
            data,
        });
    }
}
export class GenerateDailySchedulerJobError extends LightdashError {
    constructor(message, schedulerUuid, originalError) {
        super({
            message,
            name: 'GenerateDailySchedulerJobError',
            statusCode: 500,
            data: {
                schedulerUuid,
                originalError: originalError instanceof Error
                    ? originalError.message
                    : String(originalError),
            },
        });
        this.schedulerUuid = schedulerUuid;
        if (originalError instanceof Error) {
            this.stack = originalError.stack;
            this.cause = originalError;
        }
    }
}
export class LightdashProjectConfigError extends LightdashError {
    constructor(message = 'Invalid lightdash.config.yml', data = {}) {
        super({
            message,
            name: 'LightdashProjectConfigError',
            statusCode: 400,
            data,
        });
    }
}
export class CorruptedExploreError extends LightdashError {
    constructor(message = 'Explore has corrupted or missing data', data = {}) {
        super({
            message,
            name: 'CorruptedExploreError',
            statusCode: 500,
            data,
        });
    }
}
export class ChangesetConflictError extends LightdashError {
    constructor(message, data) {
        super({
            message,
            name: 'ChangesetConflictError',
            statusCode: 409,
            data,
        });
    }
}
export class InvalidSpaceStateError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'InvalidSpaceStateError',
            statusCode: 500,
            data: {},
        });
    }
}
export class JobPollTimeoutError extends LightdashError {
    constructor(jobId, timeoutMs) {
        super({
            message: `Scheduler job ${jobId} did not complete within ${timeoutMs}ms`,
            name: 'JobPollTimeoutError',
            statusCode: 504,
            data: { jobId, timeoutMs },
        });
        this.jobId = jobId;
        this.timeoutMs = timeoutMs;
    }
}
//# sourceMappingURL=errors.js.map