var c = Object.defineProperty;
var d = (r, o) => c(r, "name", { value: o, configurable: !0 });
import { ConnectError as g } from "../connect-error.js";
import { codeFromString as m } from "./code-string.js";
import { protoBase64 as s } from "../../../../../../../@bufbuild_protobuf@1.10.0/node_modules/@bufbuild/protobuf/dist/esm/proto-base64.js";
function w(r, o, t) {
  var i;
  if (o && new Headers(o).forEach((e, y) => t.metadata.append(y, e)), typeof r != "object" || r == null || Array.isArray(r))
    throw t;
  let f = t.code;
  "code" in r && typeof r.code == "string" && (f = (i = m(r.code)) !== null && i !== void 0 ? i : f);
  const n = r.message;
  if (n != null && typeof n != "string")
    throw t;
  const p = new g(n ?? "", f, o);
  if ("details" in r && Array.isArray(r.details))
    for (const e of r.details) {
      if (e === null || typeof e != "object" || Array.isArray(e) || typeof e.type != "string" || typeof e.value != "string")
        throw t;
      try {
        p.details.push({
          type: e.type,
          value: s.dec(e.value),
          debug: e.debug
        });
      } catch {
        throw t;
      }
    }
  return p;
}
d(w, "errorFromJson");
export {
  w as errorFromJson
};
