{"record":{"id":"fe1a917941960cc0","repo":"go-sql-driver/mysql","slug":"invalid-timetruncate-value-v-error-w","errorCode":null,"errorMessage":"invalid timeTruncate value: %v, error: %w","messagePattern":"invalid timeTruncate value: (.+?), error: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dsn.go","lineNumber":610,"sourceCode":"\t\t\tvar isBool bool\n\t\t\tcfg.MultiStatements, isBool = readBool(value)\n\t\t\tif !isBool {\n\t\t\t\treturn errors.New(\"invalid bool value: \" + value)\n\t\t\t}\n\n\t\t// time.Time parsing\n\t\tcase \"parseTime\":\n\t\t\tvar isBool bool\n\t\t\tcfg.ParseTime, isBool = readBool(value)\n\t\t\tif !isBool {\n\t\t\t\treturn errors.New(\"invalid bool value: \" + value)\n\t\t\t}\n\n\t\t// time.Time truncation\n\t\tcase \"timeTruncate\":\n\t\t\tcfg.timeTruncate, err = time.ParseDuration(value)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid timeTruncate value: %v, error: %w\", value, err)\n\t\t\t}\n\n\t\t// I/O read Timeout\n\t\tcase \"readTimeout\":\n\t\t\tcfg.ReadTimeout, err = time.ParseDuration(value)\n\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t// Reject read-only connections\n\t\tcase \"rejectReadOnly\":\n\t\t\tvar isBool bool\n\t\t\tcfg.RejectReadOnly, isBool = readBool(value)\n\t\t\tif !isBool {\n\t\t\t\treturn errors.New(\"invalid bool value: \" + value)\n\t\t\t}\n\n\t\t// Server public key","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/03d76c7e07908e255ce62d126d07ede3f2365d86/dsn.go#L592-L628","documentation":"The 'timeTruncate' DSN parameter is parsed with time.ParseDuration and controls truncation of scanned time values to the given granularity (e.g. \"1s\" drops sub-second precision). This error wraps the ParseDuration failure when the value is not a valid Go duration string.","triggerScenarios":"A DSN containing '?timeTruncate=...' with a value time.ParseDuration rejects, e.g. 'timeTruncate=second', 'timeTruncate=', or 'timeTruncate=1.5' (no unit).","commonSituations":"Confusing the parameter for a human-readable word like 'seconds' or 'minute'; passing a numeric without a unit; copy-paste from documentation that omits the unit.","solutions":["Use a valid Go duration such as '1s', '500ms', or '1m'.","Remove the timeTruncate parameter entirely if you do not need time truncation.","Confirm the value against time.ParseDuration rules (number + optional fraction + unit: ns/us/ms/s/m/h)."],"exampleFix":"// before\nsql.Open(\"mysql\", \"user@tcp(127.0.0.1:3306)/db?parseTime=true&timeTruncate=second\")\n// after\nsql.Open(\"mysql\", \"user@tcp(127.0.0.1:3306)/db?parseTime=true&timeTruncate=1s\")","handlingStrategy":"validation","validationCode":"// Validate the duration string before building the DSN.\nimport \"time\"\nif _, err := time.ParseDuration(timeTruncateVal); err != nil {\n    return fmt.Errorf(\"timeTruncate must be a duration: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"// ParseDSN/DSN-Format errors are returned from ParseDSN; check the error.\nif _, err := mysql.ParseDSN(dsn); err != nil {\n    return err\n}","preventionTips":["Remember timeTruncate takes a Go duration (e.g. 1s), not a word.","Reuse time.ParseDuration in a unit test for any DSN you assemble.","Omit timeTruncate unless you specifically need sub-second truncation."],"tags":["go","mysql","dsn","config","time"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}