// SPDX-License-Identifier: Apache-2.0
/**
 * Exception thrown when the execution of the Helm executable fails.
 */
export class HelmExecutionException extends Error {
    /**
     * The default message to use when no message is provided
     */
    static DEFAULT_MESSAGE = 'Execution of the Helm command failed with exit code: %d';
    /**
     * The non-zero system exit code returned by the Helm executable or the operating system
     */
    exitCode;
    /**
     * The standard output of the Helm executable
     */
    stdOut;
    /**
     * The standard error of the Helm executable
     */
    stdErr;
    constructor(exitCode, messageOrStdOutOrCause, stdErrorOrCause, stdErrorParameter) {
        let message;
        let cause;
        let stdOut = '';
        let stdError = '';
        if (messageOrStdOutOrCause instanceof Error) {
            // Constructor with exitCode and cause
            message = HelmExecutionException.DEFAULT_MESSAGE.replace('%d', exitCode.toString());
            cause = messageOrStdOutOrCause;
        }
        else if (typeof messageOrStdOutOrCause === 'string') {
            if (stdErrorOrCause instanceof Error) {
                // Constructor with exitCode, message, and cause
                message = messageOrStdOutOrCause;
                cause = stdErrorOrCause;
            }
            else if (typeof stdErrorOrCause === 'string') {
                if (stdErrorParameter) {
                    // Constructor with exitCode, message, stdOut, and stdErr
                    message = messageOrStdOutOrCause;
                    stdOut = stdErrorOrCause;
                    stdError = stdErrorParameter;
                }
                else {
                    // Constructor with exitCode, stdOut, and stdErr
                    message = HelmExecutionException.DEFAULT_MESSAGE.replace('%d', exitCode.toString());
                    stdOut = messageOrStdOutOrCause;
                    stdError = stdErrorOrCause;
                }
            }
            else {
                // Constructor with just exitCode
                message = HelmExecutionException.DEFAULT_MESSAGE.replace('%d', exitCode.toString());
            }
        }
        else {
            // Constructor with just exitCode
            message = HelmExecutionException.DEFAULT_MESSAGE.replace('%d', exitCode.toString());
        }
        super(message);
        this.name = 'HelmExecutionException';
        this.exitCode = exitCode;
        this.stdOut = stdOut;
        this.stdErr = stdError;
        if (cause) {
            this.cause = cause;
        }
    }
    /**
     * Returns the exit code returned by the Helm executable or the operating system.
     * @returns The exit code returned by the Helm executable or the operating system
     */
    getExitCode() {
        return this.exitCode;
    }
    /**
     * Returns the standard output of the Helm executable.
     * @returns The standard output of the Helm executable
     */
    getStdOut() {
        return this.stdOut;
    }
    /**
     * Returns the standard error of the Helm executable.
     * @returns The standard error of the Helm executable
     */
    getStdErr() {
        return this.stdErr;
    }
    /**
     * Returns a string representation of the exception.
     * @returns A string representation of the exception
     */
    toString() {
        return `HelmExecutionException{message=${this.message}, exitCode=${this.getExitCode()}, stdOut='${this.getStdOut()}', stdErr='${this.getStdErr()}'}`;
    }
}
//# sourceMappingURL=helm-execution-exception.js.map