{"record":{"id":"141f9fe5b8e5e33a","repo":"juicedata/juicefs","slug":"parse-url-s-failed-s-141f9f","errorCode":null,"errorMessage":"parse url %s failed: %s","messagePattern":"parse url (.+?) failed: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/object/sql.go","lineNumber":175,"sourceCode":"\t\t}\n\t}\n\treturn generateListResult(objs, limit)\n}\n\nfunc newSQLStore(driver, addr, user, password string) (ObjectStorage, error) {\n\tvar err error\n\turi := addr\n\tif user != \"\" {\n\t\turi = user + \":\" + password + \"@\" + addr\n\t}\n\tvar searchPath string\n\tif driver == \"postgres\" {\n\t\turi = \"postgres://\" + uri\n\t\tdriver = \"pgx\"\n\n\t\tparse, err := url.Parse(uri)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"parse url %s failed: %s\", uri, err)\n\t\t}\n\t\tsearchPath = parse.Query().Get(\"search_path\")\n\t\tif searchPath != \"\" {\n\t\t\tif len(strings.Split(searchPath, \",\")) > 1 {\n\t\t\t\treturn nil, fmt.Errorf(\"currently, only one schema is supported in search_path\")\n\t\t\t}\n\t\t}\n\t}\n\tengine, err := xorm.NewEngine(driver, uri)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"open %s: %s\", uri, err)\n\t}\n\tswitch logger.Level { // make xorm less verbose\n\tcase logrus.TraceLevel:\n\t\tengine.SetLogLevel(log.LOG_DEBUG)\n\tcase logrus.DebugLevel:\n\t\tengine.SetLogLevel(log.LOG_INFO)\n\tcase logrus.InfoLevel, logrus.WarnLevel:","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/sql.go#L157-L193","documentation":"newSQLStore parses the metadata URL with net/url.Parse after normalizing postgres-style addresses to 'postgres://...'. If the string is not a valid URL (bad characters, malformed host/percent-encoding), construction of the SQL object store fails before any database connection is attempted.","triggerScenarios":"Passing a metadata address like 'postgres://user:pa ss@host/db', an address with unescaped special characters ('%', spaces, control chars), or otherwise unparseable URL syntax for a postgres driver store.","commonSituations":"Special characters in the database password that are not percent-encoded (e.g. @, /, #, space) when building the JuiceFS metadata URL; copying a connection string with surrounding whitespace or brackets.","solutions":["Percent-encode special characters in user/password: use url.QueryEscape or the escape function JuiceFS provides, e.g. 'postgres://user:p%40ss@host/db'.","Verify the URL has scheme, host, and database in proper form: postgres://user:password@host:port/dbname?params.","Trim whitespace and remove stray quotes/brackets from the metadata URL."],"exampleFix":"// before\nmeta := \"postgres://juicefs:p@ssw@rd@127.0.0.1:5432/jfs\"\n// after (percent-encode '@' in password)\nmeta := \"postgres://juicefs:p%40ssw%40rd@127.0.0.1:5432/jfs\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(metaURL)\nif err != nil {\n    return fmt.Errorf(\"invalid metadata URL: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"store, err := newSQLStore(ctx, \"postgres\", addr, ak, sk)\nif err != nil && strings.HasPrefix(err.Error(), \"parse url\") {\n    return fmt.Errorf(\"percent-encode special chars in the metadata URL: %w\", err)\n}","preventionTips":["Percent-encode username/password with url.QueryEscape or juicefs escape before composing the URL.","Keep the metadata URL in a config file and validate it with url.Parse at startup.","Avoid copy-pasting connection strings with shell artifacts (quotes, whitespace)."],"tags":["sql","url","postgres","config"],"backgroundTag":"invalid-url","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}