"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var errors_exports = {};
__export(errors_exports, {
  DockerError: () => DockerError,
  NonZeroExitError: () => NonZeroExitError
});
module.exports = __toCommonJS(errors_exports);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class NonZeroExitError extends Error {
  constructor(code, message) {
    if (message) {
      message = `: ${message}`;
    } else {
      message = "";
    }
    super(`Process exited with error code ${code}${message}`);
    this.code = code;
  }
  code;
}
class DockerError extends Error {
  constructor(message, code, textCode) {
    super(message);
    this.code = code;
    this.textCode = textCode;
  }
  code;
  textCode;
  static accept(error, ...codes) {
    if (!(error instanceof DockerError) || !codes.includes(error.code)) {
      throw error;
    }
  }
}
((DockerError2) => {
  function adapt(source) {
    return source.catch((e) => {
      throw translate(e);
    });
  }
  DockerError2.adapt = adapt;
  function translate(error) {
    if (!(error instanceof Error)) {
      return new Error(`${error}`);
    }
    const parsed = error.message.match(/^\(HTTP code (\d+)\) ([^-]+) - (.*)$/);
    if (parsed === null) {
      return error;
    }
    const [, status, textCode, message] = parsed;
    let text = message.trim();
    if (text === "") {
      text = textCode;
    }
    return new DockerError2(`${text} (${status})`, Number.parseInt(status), textCode.replace(" ", "-"));
  }
  DockerError2.translate = translate;
})(DockerError || (DockerError = {}));
//# sourceMappingURL=errors.js.map
