{"record":{"id":"898c8de987f7dcf2","repo":"googleapis/mcp-toolbox","slug":"errors-encountered-when-converting-values-w-898c8d","errorCode":null,"errorMessage":"errors encountered when converting values: %w","messagePattern":"errors encountered when converting values: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/mysql/mysql.go","lineNumber":172,"sourceCode":"\t}\n\n\tout := []any{}\n\tfor results.Next() {\n\t\terr := results.Scan(values...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to parse row: %w\", err)\n\t\t}\n\t\trow := orderedmap.Row{}\n\t\tfor i, name := range cols {\n\t\t\tval := rawValues[i]\n\t\t\tif val == nil {\n\t\t\t\trow.Add(name, nil)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconvertedValue, err := mysqlcommon.ConvertToType(colTypes[i], val)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"errors encountered when converting values: %w\", err)\n\t\t\t}\n\t\t\trow.Add(name, convertedValue)\n\t\t}\n\t\tout = append(out, row)\n\t}\n\n\tif err := results.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"errors encountered during row iteration: %w\", err)\n\t}\n\n\treturn out, nil\n}\n\nfunc initMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string, queryParams map[string]string) (*sql.DB, error) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mysql/mysql.go#L154-L190","documentation":"This error is returned when mysqlcommon.ConvertToType fails to convert a raw driver value ([]byte) into the appropriate Go type for the column's declared type. The library scans values as raw bytes and converts them afterwards; when a value does not fit the column type reported by the server, conversion fails and the whole query result is abandoned.","triggerScenarios":"Running a query through the mysql run-sql tool where a returned column's value cannot be parsed according to its MySQL column type — e.g. a TIME value out of range, an invalid DATE/DATETIME string, or a numeric column containing non-numeric data.","commonSituations":"Servers returning zero or out-of-range temporal values ('0000-00-00', '803:20:05') with strict parsing enabled via parseTime=true, corrupted data in legacy tables, or replicas with divergent column types from the primary.","solutions":["Fix the offending data at the source (the wrapped error identifies the column/value).","Sanitize in SQL: use NULLIF, COALESCE, or CAST to avoid unparseable temporal/numeric values.","Configure the MySQL server for zero-date handling that matches expectations (sql_mode NO_ZERO_DATE / convert zero dates).","If driver conversion rules are the issue, upgrade github.com/go-sql-driver/mysql and the common conversion package."],"exampleFix":"// before\nSELECT updated_at FROM legacy_orders;\n// after\nSELECT NULLIF(updated_at, '0000-00-00 00:00:00') AS updated_at FROM legacy_orders;","handlingStrategy":"validation","validationCode":"// Check temporal/numeric columns for unparseable values before conversion:\nvar bad int\nerr := db.QueryRow(`SELECT COUNT(*) FROM t WHERE updated_at = '0000-00-00 00:00:00' OR updated_at IS NULL`).Scan(&bad)\nif err != nil { return err }\nif bad > 0 {\n    return fmt.Errorf(\"%d rows contain zero-dates; clean them or NULLIF in the query\", bad)\n}","typeGuard":null,"tryCatchPattern":"out, err := toolboxClient.InvokeTool(ctx, \"run-sql\", params)\nif err != nil && strings.Contains(err.Error(), \"errors encountered when converting values\") {\n    // the wrapped error names the column/value; rewrite query with NULLIF/COALESCE and retry\n    return fmt.Errorf(\"value conversion failed: %w\", err)\n}","preventionTips":["Sanitize zero/invalid dates at the database level or in the SELECT with NULLIF/COALESCE.","Enable strict sql_mode (STRICT_ALL_TABLES, NO_ZERO_DATE) so bad values are rejected at write time.","CAST numeric columns explicitly when data quality is uncertain.","Run data-quality checks on legacy tables before exposing them via run-sql."],"tags":["mysql","type-conversion","sql","database"],"backgroundTag":"value-conversion-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}