@@ -48,23 +48,32 @@ type FileScanner interface {
4848}
4949
5050type fileScanner struct {
51- sourcePath string
52- db * sql.DB
53- store storeapi.Storage
54- loader * mydump.MDLoader
55- logger log.Logger
56- config * SDKConfig
51+ redactedSourcePath string
52+ db * sql.DB
53+ store storeapi.Storage
54+ loader * mydump.MDLoader
55+ logger log.Logger
56+ config * SDKConfig
5757}
5858
59+ const redactedInvalidSourcePath = "<redacted-invalid-source>"
60+
5961// NewFileScanner creates a new FileScanner
6062func NewFileScanner (ctx context.Context , sourcePath string , db * sql.DB , cfg * SDKConfig ) (FileScanner , error ) {
63+ redactedSourcePath := ast .RedactURL (sourcePath )
64+ parseErrorSourcePath := redactedSourcePath
65+ if parseErrorSourcePath == sourcePath {
66+ // ast.RedactURL leaves malformed or unsupported URLs unchanged.
67+ // Avoid exposing the original source in outward-facing parse errors.
68+ parseErrorSourcePath = redactedInvalidSourcePath
69+ }
6170 u , err := objstore .ParseBackend (sourcePath , nil )
6271 if err != nil {
63- return nil , errors .Annotatef (ErrParseStorageURL , "source=%s, err=%v " , sourcePath , err )
72+ return nil , errors .Annotatef (ErrParseStorageURL , "source=%s" , parseErrorSourcePath )
6473 }
6574 store , err := objstore .New (ctx , u , & storeapi.Options {})
6675 if err != nil {
67- return nil , errors .Annotatef (ErrCreateExternalStorage , "source=%s, err=%v" , sourcePath , err )
76+ return nil , errors .Annotatef (ErrCreateExternalStorage , "source=%s, err=%v" , redactedSourcePath , err )
6877 }
6978
7079 ldrCfg := mydump.LoaderConfig {
@@ -90,24 +99,24 @@ func NewFileScanner(ctx context.Context, sourcePath string, db *sql.DB, cfg *SDK
9099 loader , err := mydump .NewLoaderWithStore (ctx , ldrCfg , store , loaderOptions ... )
91100 if err != nil {
92101 if loader == nil || ! errors .ErrorEqual (err , common .ErrTooManySourceFiles ) {
93- return nil , errors .Annotatef (ErrCreateLoader , "source=%s, charset=%s, err=%v" , sourcePath , cfg .charset , err )
102+ return nil , errors .Annotatef (ErrCreateLoader , "source=%s, charset=%s, err=%v" , redactedSourcePath , cfg .charset , err )
94103 }
95104 }
96105
97106 return & fileScanner {
98- sourcePath : sourcePath ,
99- db : db ,
100- store : store ,
101- loader : loader ,
102- logger : cfg .logger ,
103- config : cfg ,
107+ redactedSourcePath : redactedSourcePath ,
108+ db : db ,
109+ store : store ,
110+ loader : loader ,
111+ logger : cfg .logger ,
112+ config : cfg ,
104113 }, nil
105114}
106115
107116func (s * fileScanner ) CreateSchemasAndTables (ctx context.Context ) error {
108117 dbMetas := s .loader .GetDatabases ()
109118 if len (dbMetas ) == 0 {
110- return errors .Annotatef (ErrNoDatabasesFound , "source=%s" , s .sourcePath )
119+ return errors .Annotatef (ErrNoDatabasesFound , "source=%s" , s .redactedSourcePath )
111120 }
112121
113122 // Create all schemas and tables
@@ -121,7 +130,7 @@ func (s *fileScanner) CreateSchemasAndTables(ctx context.Context) error {
121130
122131 err := importer .Run (ctx , dbMetas )
123132 if err != nil {
124- return errors .Annotatef (ErrCreateSchema , "source=%s, db_count=%d, err=%v" , s .sourcePath , len (dbMetas ), err )
133+ return errors .Annotatef (ErrCreateSchema , "source=%s, db_count=%d, err=%v" , s .redactedSourcePath , len (dbMetas ), err )
125134 }
126135
127136 return nil
@@ -155,7 +164,7 @@ func (s *fileScanner) CreateSchemaAndTableByName(ctx context.Context, schema, ta
155164 Tables : []* mydump.MDTableMeta {tblMeta },
156165 }})
157166 if err != nil {
158- return errors .Annotatef (ErrCreateSchema , "source=%s, schema=%s, table=%s, err=%v" , s .sourcePath , schema , table , err )
167+ return errors .Annotatef (ErrCreateSchema , "source=%s, schema=%s, table=%s, err=%v" , s .redactedSourcePath , schema , table , err )
159168 }
160169
161170 return nil
@@ -202,7 +211,7 @@ func (s *fileScanner) GetTotalSize(ctx context.Context) int64 {
202211func (s * fileScanner ) EstimateImportDataSize (ctx context.Context ) (* ImportDataSizeEstimate , error ) {
203212 dbMetas := s .loader .GetDatabases ()
204213 if len (dbMetas ) == 0 {
205- return nil , errors .Annotatef (ErrNoDatabasesFound , "source=%s" , s .sourcePath )
214+ return nil , errors .Annotatef (ErrNoDatabasesFound , "source=%s" , s .redactedSourcePath )
206215 }
207216
208217 result := & ImportDataSizeEstimate {
0 commit comments