{"record":{"id":"382d6cd057d347c2","repo":"crowdsecurity/crowdsec","slug":"while-parsing-s-w","errorCode":null,"errorMessage":"while parsing %s: %w","messagePattern":"while parsing (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/cloudwatch/config.go","lineNumber":222,"sourceCode":"\n\targs := strings.Split(dsn, \"?\")\n\tif len(args) != 2 {\n\t\treturn errors.New(\"query is mandatory (at least start_date and end_date or backlog)\")\n\t}\n\n\tfrags := strings.Split(args[0], \":\")\n\tif len(frags) != 2 {\n\t\treturn errors.New(\"cloudwatch path must contain group and stream : /my/group/name:stream/name\")\n\t}\n\n\ts.Config.GroupName = frags[0]\n\ts.Config.StreamName = &frags[1]\n\ts.Config.Labels = labels\n\ts.Config.UniqueId = uuid\n\n\tu, err := url.ParseQuery(args[1])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while parsing %s: %w\", dsn, err)\n\t}\n\n\tfor k, v := range u {\n\t\tswitch k {\n\t\tcase \"log_level\":\n\t\t\tif len(v) != 1 {\n\t\t\t\treturn errors.New(\"expected zero or one value for 'log_level'\")\n\t\t\t}\n\n\t\t\tlvl, err := log.ParseLevel(v[0])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unknown level %s: %w\", v[0], err)\n\t\t\t}\n\n\t\t\ts.logger.Logger.SetLevel(lvl)\n\t\tcase \"profile\":\n\t\t\tif len(v) != 1 {\n\t\t\t\treturn errors.New(\"expected zero or one value for 'profile'\")","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/cloudwatch/config.go#L204-L240","documentation":"ConfigureByDSN parses the query-string portion of a cloudwatch DSN (e.g. cloudwatch://...?log_group=...&stream=...). If url.ParseQuery rejects that portion (malformed percent-encoding, stray '%' or bad escapes), the source configuration fails with this wrapped error.","triggerScenarios":"Calling ConfigureByDSN with a DSN whose args[1] is not a valid URL query string — raw '%' characters, unescaped '&=' misuse, or invalid percent escapes like '%zz'.","commonSituations":"Stream names or labels pasted into the DSN containing special characters that weren't percent-encoded, hand-written acquis.yaml DSNs with typos, or programmatically assembled DSNs skipping url.QueryEscape.","solutions":["Percent-encode special characters in DSN parameter values (use url.QueryEscape when building programmatically).","Fix typos in the DSN query string (stray %, unbalanced separators).","Simplify: remove problematic characters from labels/stream names, or use the full config-file form instead of a DSN."],"exampleFix":"// before\ncloudwatch://us-east-1/MyGroup?labels=100%done&stream=app\n// after\ncloudwatch://us-east-1/MyGroup?labels=100%25done&stream=app","handlingStrategy":"validation","validationCode":"if _, err := url.ParseQuery(queryPart); err != nil {\n    return fmt.Errorf(\"malformed DSN query %q: %w\", queryPart, err)\n}","typeGuard":null,"tryCatchPattern":"if err := ConfigureByDSN(ctx, src, dsn); err != nil {\n    return fmt.Errorf(\"cannot configure cloudwatch from DSN %q: %w\", dsn, err)\n}","preventionTips":["Percent-encode DSN parameter values with url.QueryEscape","Avoid raw %, &, = in labels and stream names inside DSNs","Prefer acquis.yaml structured config over long hand-written DSNs"],"tags":["aws","cloudwatch","dsn","url-parsing"],"backgroundTag":"invalid-url-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}