{"record":{"id":"136f26914cdbe8bc","repo":"MyCATApache/Mycat-Server","slug":"unexpected-exception-e-getmessage","errorCode":null,"errorMessage":"Unexpected exception: ${e.getMessage()}","messagePattern":"Unexpected exception: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/jdbc/mongodb/MongoDriver.java","lineNumber":49,"sourceCode":"\t\t}catch (SQLException e){\n\t\t    LOGGER.error(\"initError\",e);\n\t\t}\n\t}\n\n\n\t@Override\n\tpublic Connection connect(String url, Properties info) throws SQLException {\n\t\tMongoClientURI mcu = null;\n\t\tif ((mcu = parseURL(url, info)) == null) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tMongoConnection result = null;\n\t\t//System.out.print(info);\n\t\ttry{\n\t\t\tresult = new MongoConnection(mcu, url);\n\t\t}catch (Exception e){\n\t\t\tthrow new SQLException(\"Unexpected exception: \" + e.getMessage(), e);\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\t\n\tprivate MongoClientURI parseURL(String url, Properties defaults) {\n\t\tif (url == null) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\tif (!StringUtils.startsWithIgnoreCase(url, PREFIX)) {\t\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t//删掉开头的 jdbc:\n\t\t//url = url.replace(URL_JDBC, \"\");\n\n\t\t//替换user:","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/jdbc/mongodb/MongoDriver.java#L31-L67","documentation":"MongoDriver.connect wraps construction of MongoConnection in a try-catch and rethrows any exception as SQLException(\"Unexpected exception: <message>\", e). It signals that the underlying MongoDB connection URI/URI parsing or MongoConnection construction failed; the original cause is preserved as the chained cause.","triggerScenarios":"new MongoConnection(mcu, url) throws inside connect() — typically bad MongoClientURI parsing (malformed mongodb:// URL, bad hosts/credentials) or a MongoClient constructor failure.","commonSituations":"Typo in the JDBC URL (e.g. 'mongodb:host1' instead of 'mongodb://host1'), unparseable host/port or username/password options, missing MongoDB server so the URI parser or client setup throws.","solutions":["Check the chained cause (e.getCause()) to see the real failure — the wrapper message is generic","Validate the URL is a well-formed mongodb:// URI with host[:port] before configuring the MyCat dataNode","Verify MongoDB server reachability and credentials in the URI","Check parseURL in MongoDriver for the exact URI format this driver expects"],"exampleFix":"// before\njdbc:mysql://... (mongodb node configured with url = \"mongodb:host1:27017/db\")\n\n// after\nurl = \"mongodb://host1:27017/db\"","handlingStrategy":"validation","validationCode":"if (!url.startsWith(\"mongodb://\")) {\n    throw new IllegalArgumentException(\"MongoDB JDBC url must start with mongodb:// : \" + url);\n}\n// also validate host:port presence\nURI u = new URI(url.substring(\"mongodb:\".length()));\nif (u.getHost() == null) throw new IllegalArgumentException(\"missing host in mongodb url\");","typeGuard":null,"tryCatchPattern":"try {\n    Connection c = driver.connect(url, info);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unexpected exception\")) {\n        Throwable cause = e.getCause();\n        // log cause; fix url/credentials\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always inspect getCause() — the outer message hides the real error","Test mongodb URIs with the MongoDB URI parser before deploying MyCat configs","Keep credentials and hosts in config, not concatenated strings, to avoid malformed URLs"],"tags":["jdbc","mongodb","driver","connection","url"],"backgroundTag":"http-request-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}