MCPcopy Create free account
hub / github.com/MetaMask/rpc-errors / parseOpts

Function parseOpts

src/errors.ts:284–301  ·  view source on GitHub ↗

* Get an error message and optional data from an options bag. * * @param arg - The error message or options bag. * @returns A tuple containing the error message and optional data.

(
  arg?: JsonRpcErrorsArg<Data>,
)

Source from the content-addressed store, hash-verified

282 * @returns A tuple containing the error message and optional data.
283 */
284function parseOpts<Data extends OptionalDataWithOptionalCause>(
285 arg?: JsonRpcErrorsArg<Data>,
286): [message?: string | undefined, data?: Data | undefined] {
287 if (arg) {
288 if (typeof arg === 'string') {
289 return [arg];
290 } else if (typeof arg === 'object' && !Array.isArray(arg)) {
291 const { message, data } = arg;
292
293 if (message && typeof message !== 'string') {
294 throw new Error('Must specify string message.');
295 }
296 return [message ?? undefined, data];
297 }
298 }
299
300 return [];
301}

Callers 2

getJsonRpcErrorFunction · 0.85
getEthProviderErrorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…