How does Metamask log rpc method errors?

When I call an RPC method such as eth_requestAccounts, the error that I catch is not an instanceof Error. I was wondering how and where Metamask performs this logging. Is there some sort of middleware that processes an Error into an object containing code and message fields?

I also know that this cleanErrorStack() (MetaMask/metamask-extension/blob/76a2a9bb8b6ea04025328d36404ac3b59121dfc8/app/scripts/lib/cleanErrorStack.js#L6-L22) method gets used in a few places to process the output. However, it seems to me to be the case that it is still an Error object that is outputted. Not a typical Javascript object such as { code: 4001, message: "lorem ipsum" }

I’m also aware of how the EthereumProviderError is used here (MetaMask/eth-rpc-errors/blob/22089c14bec0ee92188cee58f7c02dfbb605cf0e/src/errors.ts#L119-L126).

I pasted the log below from my chrome developer console to demonstrate what I mean because I can’t paste images yet as a new member.

Note: my parenthesized links are hosted on https://github.com/ if you want to refer to them.

ethereum.request( {method: "eth_requestAccounts"}).then(console.log)
.catch(e => console.log(e instanceof Error, typeof e, e))

Promise {<pending>}
----------------------------------------
inpage.js:1 MetaMask - RPC Error: User rejected the request. 
{code: 4001, message: "User rejected the request."}

(anonymous) @ inpage.js:1
(anonymous) @ inpage.js:17
_runReturnHandlers @ inpage.js:17
_processRequest @ inpage.js:17
async function (async)
_processRequest @ inpage.js:17
_handle @ inpage.js:17
handle @ inpage.js:17
_rpcRequest @ inpage.js:1
(anonymous) @ inpage.js:1
request @ inpage.js:1
(anonymous) @ VM312:1
----------------------------------------
VM312:1 Object false object {
    code: 4001,
    message: "User rejected the request.",
    stack: "{\n  \"code\": 4001,\n  \"message\": \"User rejected the …beogaeaoehlefnkodbefgpgknn/background.js:86:57700"}code: 4001message: "User rejected the request."stack: "{\n  \"code\": 4001,\n  \"message\": \"User rejected the request.\",\n  \"stack\": \"Error: User rejected the request.\\n    at new o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:380997)\\n    at new r.EthereumProviderError (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:381500)\\n    at s (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:383653)\\n    at Object.userRejectedRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:384881)\\n    at r.PermissionsController.rejectPermissionsRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:55203)\\n    at Object.rejectPermissionsRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:163826)\\n    at s.<anonymous> (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:139005)\\n    at d (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:21107)\\n    at s.a.emit (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:24093)\\n    at _ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11003)\\n    at w (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:10818)\\n    at s.v.push (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11629)\\n    at t.exports._write (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:123:268102)\\n    at v (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:23999)\\n    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:27177\\n    at t.exports.y.write (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:27204)\\n    at t.exports.m (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:16198)\\n    at d (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:21107)\\n    at t.exports.a.emit (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:24093)\\n    at _ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11003)\\n    at w (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:10818)\\n    at t.exports.v.push (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11629)\\n    at t.exports._onMessage (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:86:57850)\\n    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:86:57700\"\n
}\n  at new o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:380997)\n  at new r.EthereumProviderError (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:381500)\n  at s (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:383653)\n  at Object.userRejectedRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:77:384881)\n  at r.PermissionsController.rejectPermissionsRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:55203)\n  at Object.rejectPermissionsRequest (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:163826)\n  at s.<anonymous> (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:139005)\n  at d (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:21107)\n  at s.a.emit (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:24093)\n  at _ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11003)\n  at w (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:10818)\n  at s.v.push (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11629)\n  at t.exports._write (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:123:268102)\n  at v (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:23999)\n  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:27177\n  at t.exports.y.write (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:27204)\n  at t.exports.m (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:16198)\n  at d (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:21107)\n  at t.exports.a.emit (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:51:24093)\n  at _ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11003)\n  at w (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:10818)\n  at t.exports.v.push (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:147:11629)\n  at t.exports._onMessage (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:86:57850)\n  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:86:57700"__proto__: