{"record":{"id":"3f64c5f7dc9fa716","repo":"gchq/CyberChef","slug":"error-tostring-this-error-could-be-caused-by","errorCode":null,"errorMessage":"${error.toString()}\n\nThis error could be caused by one of the following:\n - An invalid Resolver URL\n","messagePattern":"(.+?)\n\nThis error could be caused by one of the following:\n - An invalid Resolver URL\n","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/DNSOverHTTPS.mjs","lineNumber":101,"sourceCode":"                name: \"Disable DNSSEC validation\",\n                type: \"boolean\",\n                value: false\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {JSON}\n     */\n    run(input, args) {\n        const [resolver, requestType, justAnswer, DNSSEC] = args;\n        let url = URL;\n        try {\n            url = new URL(resolver);\n        } catch (error) {\n            throw new OperationError(error.toString() +\n            \"\\n\\nThis error could be caused by one of the following:\\n\" +\n            \" - An invalid Resolver URL\\n\");\n        }\n        const params = {name: input, type: requestType, cd: DNSSEC};\n\n        url.search = new URLSearchParams(params);\n\n        return fetch(url, {headers: {\"accept\": \"application/dns-json\"}}).then(response => {\n            return response.json();\n        }).then(data => {\n            if (justAnswer) {\n                return extractData(data.Answer);\n            }\n            return data;\n        }).catch(e => {\n            throw new OperationError(`Error making request to ${url}\\n${e.toString()}`);\n        });\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/DNSOverHTTPS.mjs#L83-L119","documentation":"Thrown by DNS over HTTPS run() when `new URL(resolver)` raises - i.e. the Resolver argument is not a parseable absolute URL. The original TypeError from the URL constructor is stringified and re-wrapped as an OperationError with a hint. This fires synchronously before any network call.","triggerScenarios":"Resolver set to a value that is not a valid absolute URL: missing scheme (e.g. 'cloudflare-dns.com/dns-query'), a relative path, 'undefined'/'[object Object]' from a malformed option value, or a typo. The editableOption default values are valid, so this typically requires the user to edit/add a custom resolver.","commonSituations":"Typing a resolver without the https:// scheme; pasting a domain-only resolver; a custom resolver value that was constructed from an object instead of a string; deleting the resolver field.","solutions":["Use the full absolute URL including scheme, e.g. 'https://cloudflare-dns.com/dns-query' or 'https://dns.google.com/resolve'.","If adding a custom DoH endpoint, ensure it accepts GET with name= and type= query parameters and returns application/dns-json.","Restore one of the built-in Google/Cloudflare defaults.","Check for stray whitespace or object-stringified values in the Resolver field."],"exampleFix":"// before\nResolver: cloudflare-dns.com/dns-query\n\n// after\nResolver: https://cloudflare-dns.com/dns-query","handlingStrategy":"validation","validationCode":"function isValidResolverUrl(resolver) {\n    try {\n        const u = new URL(resolver);\n        return u.protocol === \"http:\" || u.protocol === \"https:\";\n    } catch {\n        return false;\n    }\n}","typeGuard":"/** @returns {boolean} */\nfunction isAbsoluteHttpUrl(s) {\n    try {\n        const u = new URL(String(s));\n        return u.protocol === \"http:\" || u.protocol === \"https:\";\n    } catch {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    result = await dnsOverHttps.run(input, args);\n} catch (e) {\n    if (e instanceof OperationError && /invalid Resolver URL|TypeError: Invalid URL/i.test(e.message)) {\n        // prompt user to enter a valid https:// resolver URL\n    } else throw e;\n}","preventionTips":["Always include the https:// scheme in custom DoH resolver URLs.","Prefer the built-in Google/Cloudflare defaults unless a custom resolver is required.","Validate resolver URLs with `new URL(...)` before adding them to a recipe.","Strip stray whitespace and object-stringified values from the Resolver field."],"tags":["network","dns","url-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}