"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutError = exports.ExpiredQueryError = exports.ResultsExpiredError = exports.S3Error = exports.ReadFileError = exports.SshTunnelError = exports.ScreenshotError = exports.getErrorMessage = exports.DeprecatedRouteError = exports.NotImplementedError = exports.GoogleSheetsQuotaError = exports.GoogleSheetsTransientError = exports.GoogleSheetsScopeError = exports.UnexpectedGoogleSheetsError = exports.GoogleChatError = exports.MsTeamsError = exports.SlackFileUploadError = exports.SlackError = exports.SlackInstallationNotFoundError = exports.PaginationError = exports.NotEnoughResults = exports.MissingConfigError = exports.AlreadyExistsError = exports.AlreadyProcessingError = exports.SmptError = exports.WarehouseQueryError = exports.WarehouseConnectionError = exports.InvalidUser = exports.NotSupportedError = exports.NotFoundError = exports.DbtError = exports.FieldReferenceError = exports.CompileError = exports.ParseError = exports.UnexpectedDatabaseError = exports.InsufficientGitPermissionsError = exports.UnexpectedGitError = exports.UnexpectedIndexError = exports.UnexpectedServerError = exports.MissingWarehouseCredentialsError = exports.MissingCatalogEntryError = exports.NonCompiledModelError = exports.PayloadTooLargeError = exports.ParameterError = exports.ExpiredError = exports.AuthorizationError = exports.DeactivatedAccountError = exports.GoogleNotConnectedError = exports.ForbiddenError = exports.LightdashError = void 0;
exports.JobPollTimeoutError = exports.InvalidSpaceStateError = exports.ChangesetConflictError = exports.CorruptedExploreError = exports.LightdashProjectConfigError = exports.GenerateDailySchedulerJobError = exports.OauthAuthenticationError = exports.CustomSqlQueryForbiddenError = exports.BigqueryTokenError = exports.DatabricksTokenError = exports.SnowflakeTokenError = exports.AiAgentValidatorError = exports.AiAgentNotFoundError = exports.AiSlackMappingNotFoundError = exports.AiDuplicateSlackPromptError = void 0;
class LightdashError extends Error {
    constructor({ message, name, statusCode, data }) {
        super(message);
        this.name = name;
        this.statusCode = statusCode;
        this.data = data;
    }
}
exports.LightdashError = LightdashError;
class ForbiddenError extends LightdashError {
    constructor(message = "You don't have access to this resource or action", data = {}) {
        super({
            message,
            name: 'ForbiddenError',
            statusCode: 403,
            data,
        });
    }
}
exports.ForbiddenError = ForbiddenError;
class GoogleNotConnectedError extends LightdashError {
    constructor(message = 'Google account not connected') {
        super({
            message,
            name: 'GoogleNotConnectedError',
            statusCode: 412,
            data: {},
        });
    }
}
exports.GoogleNotConnectedError = GoogleNotConnectedError;
class DeactivatedAccountError extends LightdashError {
    constructor(message = 'Your account has been deactivated. Please contact your organization administrator.', data = {}) {
        super({
            message,
            name: 'DeactivatedAccountError',
            statusCode: 403,
            data,
        });
    }
}
exports.DeactivatedAccountError = DeactivatedAccountError;
class AuthorizationError extends LightdashError {
    constructor(message = "You don't have authorization to perform this action", data = {}) {
        super({
            message,
            name: 'AuthorizationError',
            statusCode: 401,
            data,
        });
    }
}
exports.AuthorizationError = AuthorizationError;
class ExpiredError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'ExpiredError',
            statusCode: 406,
            data: {},
        });
    }
}
exports.ExpiredError = ExpiredError;
class ParameterError extends LightdashError {
    constructor(message = 'Incorrect parameters', data = {}) {
        super({
            message,
            name: 'ParameterError',
            statusCode: 400,
            data,
        });
    }
}
exports.ParameterError = ParameterError;
class PayloadTooLargeError extends LightdashError {
    constructor(message = 'Request payload exceeds the maximum allowed size', data = {}) {
        super({
            message,
            name: 'PayloadTooLargeError',
            statusCode: 413,
            data,
        });
    }
}
exports.PayloadTooLargeError = PayloadTooLargeError;
class NonCompiledModelError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'NonCompiledModelError',
            statusCode: 400,
            data,
        });
    }
}
exports.NonCompiledModelError = NonCompiledModelError;
class MissingCatalogEntryError extends LightdashError {
    constructor(message, data) {
        super({
            message,
            name: 'MissingCatalogEntryError',
            statusCode: 400,
            data,
        });
    }
}
exports.MissingCatalogEntryError = MissingCatalogEntryError;
class MissingWarehouseCredentialsError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'MissingWarehouseCredentialsError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.MissingWarehouseCredentialsError = MissingWarehouseCredentialsError;
class UnexpectedServerError extends LightdashError {
    constructor(message = 'Something went wrong.', data = {}) {
        super({
            message,
            name: 'UnexpectedServerError',
            statusCode: 500,
            data,
        });
    }
}
exports.UnexpectedServerError = UnexpectedServerError;
class UnexpectedIndexError extends LightdashError {
    constructor(message = 'Invalid index in array.', data = {}) {
        super({
            message,
            name: 'UnexpectedIndexError',
            statusCode: 500,
            data,
        });
    }
}
exports.UnexpectedIndexError = UnexpectedIndexError;
class UnexpectedGitError extends LightdashError {
    constructor(message = 'Unexpected error in Git adapter', data = {}) {
        super({
            message,
            name: 'UnexpectedGitError',
            statusCode: 400,
            data,
        });
    }
}
exports.UnexpectedGitError = UnexpectedGitError;
/**
 * 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.
 */
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,
        });
    }
}
exports.InsufficientGitPermissionsError = InsufficientGitPermissionsError;
class UnexpectedDatabaseError extends LightdashError {
    constructor(message = 'Unexpected error in Lightdash database.', data = {}) {
        super({
            message,
            name: 'UnexpectedDatabaseError',
            statusCode: 500,
            data,
        });
    }
}
exports.UnexpectedDatabaseError = UnexpectedDatabaseError;
class ParseError extends LightdashError {
    constructor(message = 'Error parsing dbt project and lightdash metadata', data = {}) {
        super({
            message,
            name: 'ParseError',
            statusCode: 400,
            data,
        });
    }
}
exports.ParseError = ParseError;
class CompileError extends LightdashError {
    constructor(message = 'Error compiling sql from Lightdash configuration', data = {}) {
        super({
            message,
            name: 'CompileError',
            statusCode: 400,
            data,
        });
    }
}
exports.CompileError = CompileError;
class FieldReferenceError extends LightdashError {
    constructor(message = 'Failed to reference field in dbt project', data = {}) {
        super({
            message,
            name: 'FieldReferenceError',
            statusCode: 400,
            data,
        });
    }
}
exports.FieldReferenceError = FieldReferenceError;
class DbtError extends LightdashError {
    constructor(message = 'Dbt raised an error', logs = []) {
        super({
            message,
            name: 'DbtError',
            statusCode: 400,
            data: {},
        });
        this.logs = logs;
    }
}
exports.DbtError = DbtError;
class NotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotFoundError',
            statusCode: 404,
            data: {},
        });
    }
}
exports.NotFoundError = NotFoundError;
class NotSupportedError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotSupportedError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.NotSupportedError = NotSupportedError;
class InvalidUser extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'InvalidUser',
            statusCode: 404,
            data: {},
        });
    }
}
exports.InvalidUser = InvalidUser;
class WarehouseConnectionError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'WarehouseConnectionError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.WarehouseConnectionError = WarehouseConnectionError;
class WarehouseQueryError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'WarehouseQueryError',
            statusCode: 400,
            data,
        });
    }
}
exports.WarehouseQueryError = WarehouseQueryError;
class SmptError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'SmptError',
            statusCode: 500,
            data,
        });
    }
}
exports.SmptError = SmptError;
class AlreadyProcessingError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AlreadyProcessingError',
            statusCode: 409,
            data: {},
        });
    }
}
exports.AlreadyProcessingError = AlreadyProcessingError;
class AlreadyExistsError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AlreadyExistsError',
            statusCode: 409,
            data: {},
        });
    }
}
exports.AlreadyExistsError = AlreadyExistsError;
class MissingConfigError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'MissingConfigError',
            statusCode: 422,
            data: {},
        });
    }
}
exports.MissingConfigError = MissingConfigError;
class NotEnoughResults extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'NotEnoughResults',
            statusCode: 406,
            data: {},
        });
    }
}
exports.NotEnoughResults = NotEnoughResults;
class PaginationError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'PaginationError',
            statusCode: 422,
            data: {},
        });
    }
}
exports.PaginationError = PaginationError;
class SlackInstallationNotFoundError extends LightdashError {
    constructor(message = 'Could not find slack installation') {
        super({
            message,
            name: 'SlackInstallationNotFoundError',
            statusCode: 404,
            data: {},
        });
    }
}
exports.SlackInstallationNotFoundError = SlackInstallationNotFoundError;
class SlackError extends LightdashError {
    constructor(message = 'Slack API error occurred', data = {}) {
        super({
            message,
            name: 'SlackError',
            statusCode: 400,
            data,
        });
    }
}
exports.SlackError = SlackError;
class SlackFileUploadError extends LightdashError {
    constructor(message = 'Slack file upload failed', data = {}) {
        super({
            message,
            name: 'SlackFileUploadError',
            statusCode: 400,
            data,
        });
    }
}
exports.SlackFileUploadError = SlackFileUploadError;
class MsTeamsError extends LightdashError {
    constructor(message = 'Microsoft Teams API error occurred', data = {}) {
        super({
            message,
            name: 'MsTeamsError',
            statusCode: 400,
            data,
        });
    }
}
exports.MsTeamsError = MsTeamsError;
class GoogleChatError extends LightdashError {
    constructor(message = 'Google Chat API error occurred', data = {}) {
        super({
            message,
            name: 'GoogleChatError',
            statusCode: 400,
            data,
        });
    }
}
exports.GoogleChatError = GoogleChatError;
class UnexpectedGoogleSheetsError extends LightdashError {
    constructor(message = 'Unexpected error in Google sheets client', data = {}) {
        super({
            message,
            name: 'UnexpectedGoogleSheetsError',
            statusCode: 400,
            data,
        });
    }
}
exports.UnexpectedGoogleSheetsError = UnexpectedGoogleSheetsError;
/* This specific error will be used in the frontend
to show a "Re-authenticate" button in the UI for Google Sheets scope issues
*/
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,
        });
    }
}
exports.GoogleSheetsScopeError = GoogleSheetsScopeError;
class GoogleSheetsTransientError extends LightdashError {
    constructor(message = 'Unexpected error in Google Sheets API', data = {}) {
        super({
            message,
            name: 'GoogleSheetsTransientError',
            statusCode: 500,
            data,
        });
    }
}
exports.GoogleSheetsTransientError = GoogleSheetsTransientError;
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,
        });
    }
}
exports.GoogleSheetsQuotaError = GoogleSheetsQuotaError;
class NotImplementedError extends LightdashError {
    constructor(message = 'Not implemented') {
        super({
            message,
            name: 'NotImplemented',
            statusCode: 501,
            data: {},
        });
    }
}
exports.NotImplementedError = NotImplementedError;
class DeprecatedRouteError extends LightdashError {
    constructor(message = 'Deprecated route called past its removal deadline', data = {}) {
        super({
            message,
            name: 'DeprecatedRouteError',
            statusCode: 410,
            data,
        });
    }
}
exports.DeprecatedRouteError = DeprecatedRouteError;
const getErrorMessage = (e) => {
    if (e instanceof Error && e.message)
        return e.message;
    return `Unknown ${typeof e} error`;
};
exports.getErrorMessage = getErrorMessage;
class ScreenshotError extends LightdashError {
    constructor(message = 'Error capturing screenshot', data = {}) {
        super({
            message,
            name: 'ScreenshotError',
            statusCode: 500,
            data,
        });
    }
}
exports.ScreenshotError = ScreenshotError;
class SshTunnelError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'SshTunnelError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.SshTunnelError = SshTunnelError;
class ReadFileError extends LightdashError {
    constructor(message, data = {}) {
        super({
            message,
            name: 'ReadFileError',
            statusCode: 404,
            data,
        });
    }
}
exports.ReadFileError = ReadFileError;
class S3Error extends LightdashError {
    constructor(message = 'Error occurred while interacting with S3', data = {}) {
        super({
            message,
            name: 'S3Error',
            statusCode: 500,
            data,
        });
    }
}
exports.S3Error = S3Error;
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: {},
        });
    }
}
exports.ResultsExpiredError = ResultsExpiredError;
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,
        });
    }
}
exports.ExpiredQueryError = ExpiredQueryError;
class TimeoutError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'TimeoutError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.TimeoutError = TimeoutError;
class AiDuplicateSlackPromptError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiDuplicateSlackPromptError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.AiDuplicateSlackPromptError = AiDuplicateSlackPromptError;
class AiSlackMappingNotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiSlackMappingNotFoundError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.AiSlackMappingNotFoundError = AiSlackMappingNotFoundError;
class AiAgentNotFoundError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiAgentNotFoundError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.AiAgentNotFoundError = AiAgentNotFoundError;
class AiAgentValidatorError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'AiAgentValidatorError',
            statusCode: 400,
            data: {},
        });
    }
}
exports.AiAgentValidatorError = AiAgentValidatorError;
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
class SnowflakeTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'SnowflakeTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
exports.SnowflakeTokenError = SnowflakeTokenError;
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
class DatabricksTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'DatabricksTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
exports.DatabricksTokenError = DatabricksTokenError;
/* This specific error will be used in the frontend
to show a "reauthenticate" button in the UI
*/
class BigqueryTokenError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'BigqueryTokenError',
            statusCode: 401,
            data: {},
        });
    }
}
exports.BigqueryTokenError = BigqueryTokenError;
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`,
            },
        });
    }
}
exports.CustomSqlQueryForbiddenError = CustomSqlQueryForbiddenError;
class OauthAuthenticationError extends LightdashError {
    constructor(message = 'OAuth authentication error', data = {}) {
        super({
            message,
            name: 'OauthAuthenticationError',
            statusCode: 401,
            data,
        });
    }
}
exports.OauthAuthenticationError = OauthAuthenticationError;
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;
        }
    }
}
exports.GenerateDailySchedulerJobError = GenerateDailySchedulerJobError;
class LightdashProjectConfigError extends LightdashError {
    constructor(message = 'Invalid lightdash.config.yml', data = {}) {
        super({
            message,
            name: 'LightdashProjectConfigError',
            statusCode: 400,
            data,
        });
    }
}
exports.LightdashProjectConfigError = LightdashProjectConfigError;
class CorruptedExploreError extends LightdashError {
    constructor(message = 'Explore has corrupted or missing data', data = {}) {
        super({
            message,
            name: 'CorruptedExploreError',
            statusCode: 500,
            data,
        });
    }
}
exports.CorruptedExploreError = CorruptedExploreError;
class ChangesetConflictError extends LightdashError {
    constructor(message, data) {
        super({
            message,
            name: 'ChangesetConflictError',
            statusCode: 409,
            data,
        });
    }
}
exports.ChangesetConflictError = ChangesetConflictError;
class InvalidSpaceStateError extends LightdashError {
    constructor(message) {
        super({
            message,
            name: 'InvalidSpaceStateError',
            statusCode: 500,
            data: {},
        });
    }
}
exports.InvalidSpaceStateError = InvalidSpaceStateError;
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;
    }
}
exports.JobPollTimeoutError = JobPollTimeoutError;
//# sourceMappingURL=errors.js.map