mindlesscloud opened a new issue, #3725:
URL: https://github.com/apache/incubator-devlake/issues/3725

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/incubator-devlake/issues?q=is%3Aissue) and 
found no similar issues.
   
   
   ### What happened
   
   the clean-up code will be executed only if `err != nil`
   ```go
   defer func() {
                if err != nil {
                        // the clean-up code
                }
        }()
   ```
   The statement `dst, err := transform(src)` will create another local 
variable `err` which shadows the previous `err`. If the function `transform` 
returns an error, the clean-up code will not be executed.
   ```go
   for cursor.Next() {
                err = db.Fetch(cursor, src)
                if err != nil {
                        return errors.Default.Wrap(err, fmt.Sprintf("fail to 
load record from table [%s]", tmpTableName))
                }
                dst, err := transform(src)
                if err != nil {
                        return errors.Default.Wrap(err, fmt.Sprintf("failed to 
transform row %v", src))
                }
                err = batch.Add(dst)
                if err != nil {
                        return errors.Default.Wrap(err, fmt.Sprintf("push to 
BatchSave failed %v", dst))
                }
        }
   ```
   
   ### What do you expect to happen
   
   The clean-up code should be executed if something went wrong during the data 
migration.
   
   ### How to reproduce
   
   reading the  code 
https://github.com/apache/incubator-devlake/blob/5722a751eca93bbc6eb409eba829dead836d844c/helpers/migrationhelper/migrationhelper.go#L217-L249
   
   ### Anything else
   
   _No response_
   
   ### Version
   
   main
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to