(err, constructor, tag, ctx, keys)
| 1931 | } |
| 1932 | |
| 1933 | function formatError(err, constructor, tag, ctx, keys) { |
| 1934 | let message, name, stack; |
| 1935 | try { |
| 1936 | stack = getStackString(ctx, err); |
| 1937 | } catch { |
| 1938 | return ObjectPrototypeToString(err); |
| 1939 | } |
| 1940 | |
| 1941 | let messageIsGetterThatThrows = false; |
| 1942 | try { |
| 1943 | message = err.message; |
| 1944 | } catch { |
| 1945 | messageIsGetterThatThrows = true; |
| 1946 | } |
| 1947 | let nameIsGetterThatThrows = false; |
| 1948 | try { |
| 1949 | name = err.name; |
| 1950 | } catch { |
| 1951 | nameIsGetterThatThrows = true; |
| 1952 | } |
| 1953 | |
| 1954 | if (!ctx.showHidden && keys.length !== 0) { |
| 1955 | const index = ArrayPrototypeIndexOf(keys, 'stack'); |
| 1956 | if (index !== -1) { |
| 1957 | ArrayPrototypeSplice(keys, index, 1); |
| 1958 | } |
| 1959 | |
| 1960 | if (!messageIsGetterThatThrows) { |
| 1961 | const index = ArrayPrototypeIndexOf(keys, 'message'); |
| 1962 | // Only hide the property if it's a string and if it's part of the original stack |
| 1963 | if (index !== -1 && (typeof message !== 'string' || StringPrototypeIncludes(stack, message))) { |
| 1964 | ArrayPrototypeSplice(keys, index, 1); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | if (!nameIsGetterThatThrows) { |
| 1969 | const index = ArrayPrototypeIndexOf(keys, 'name'); |
| 1970 | // Only hide the property if it's a string and if it's part of the original stack |
| 1971 | if (index !== -1 && (typeof name !== 'string' || StringPrototypeIncludes(stack, name))) { |
| 1972 | ArrayPrototypeSplice(keys, index, 1); |
| 1973 | } |
| 1974 | } |
| 1975 | } |
| 1976 | name ??= 'Error'; |
| 1977 | |
| 1978 | if (ObjectPrototypeHasOwnProperty(err, 'cause') && |
| 1979 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) { |
| 1980 | ArrayPrototypePush(keys, 'cause'); |
| 1981 | } |
| 1982 | |
| 1983 | // Print errors aggregated into AggregateError |
| 1984 | try { |
| 1985 | const errors = err.errors; |
| 1986 | if (ArrayIsArray(errors) && ObjectPrototypeHasOwnProperty(err, 'errors') && |
| 1987 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) { |
| 1988 | ArrayPrototypePush(keys, 'errors'); |
| 1989 | } |
| 1990 | } catch { |
no test coverage detected
searching dependent graphs…