Skip to content

"import" throws with various projects #1058

Closed

Description

@swernerx

I am trying to use lerna for the Edge Platform. Right now I am in the phase of importing some old projects. Unfortunately, I have reproducible import issues which always seem to stop at specific commits. I am unaware of any specifics of these commits. The error message from Lerna is also not very helpful.

Expected Behavior

Importing should work on all packages.

Current Behavior

Currently Lerna throws during import with hard errors:

lerna info 1ebef2c 
lerna info b1075d6 
lerna info 3c0a15e 
lerna ERR! execute callback with error
(node:58112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'split' of undefined
(node:58112) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Possible Solution

Check where the "split" call happens and why there is a possible null value inside the code.

Steps to Reproduce (for bugs)

All the code is open source so it should be possible for others to reproduce:

This happens also when using a freshly checked-out repository. So it is probably nothing about local changes.

Vers

lerna.json

{
  "lerna": "2.4.0",
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "npmClient": "yarn",
  "useWorkspaces": true
}

lerna-debug.log

<!-- If you have a `lerna-debug.log` available, please paste it here -->
<!-- Otherwise, feel free to delete this <details> block -->

Context

Starting to use lerna.

Your Environment

Executable Version
lerna --version 2.4.0
npm --version 5.5.1
yarn --version 1.1.0
node --version 8.6.0
git --version 2.14.2
OS Version
macOS Sierra 10.12.6

Activity

  1. changed the title [-]"import" throws via various projects[/-] [+]"import" throws with various projects[/+] on Oct 8, 2017
  2. swernerx commented on Oct 8, 2017

    @swernerx
    ContributorAuthor

    I figure this is just a broken error handling as the git error which happens is not passed to the console log. Even when using debug logging.

          function (err) {
            tracker.finish();
    
            if (!err) {
              _this2.logger.success("import", "finished");
            } else {
              _this2.logger.error("import", err);
            }
    
            callback(err, !err);
          });

    I added the else block above to log the error... but I figure the uncaught exception should still be dealt with. This is the new output after adding the else block:

    lerna info 3c9f6e6 
    lerna info 4fd7d08 
    lerna info 3998aa0 
    lerna ERR! import Failed to apply commit 3998aa0.
    lerna ERR! import Error: Command failed: git am -3
    lerna ERR! import error: sha1 information is lacking or useless (packages/readable-code/package.json).
    lerna ERR! import error: could not build fake ancestor
    lerna ERR! import Applying: Release 0.1.14
    lerna ERR! import Patch failed at 0001 Release 0.1.14
    lerna ERR! import The copy of the patch that failed is found in: .git/rebase-apply/patch
    lerna ERR! import When you have resolved this problem, run "git am --continue".
    lerna ERR! import If you prefer to skip this patch, run "git am --skip" instead.
    lerna ERR! import To restore the original branch and stop patching, run "git am --abort".
    lerna ERR! import 
    lerna ERR! import Rolling back to previous HEAD (commit 234022a598b38f74c5eba543166cb810faaf19ac).
    lerna ERR! import You may try with --flatten to import flat history.
    lerna ERR! execute callback with error
    (node:3703) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'split' of undefined
    (node:3703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    
  3. swernerx commented on Oct 8, 2017

    @swernerx
    ContributorAuthor

    As suggested by the output adding --flatten works around this issue. But there seems to be another edge case related to empty patches.

    Output:

    lerna info 86791f0 
    lerna info 49e89f3 
    lerna ERR! import Failed to apply commit 49e89f3.
    lerna ERR! import Error: Command failed: git am -3
    lerna ERR! import Patch is empty.
    lerna ERR! import When you have resolved this problem, run "git am --continue".
    lerna ERR! import If you prefer to skip this patch, run "git am --skip" instead.
    lerna ERR! import To restore the original branch and stop patching, run "git am --abort".
    lerna ERR! import 
    lerna ERR! import Rolling back to previous HEAD (commit 234022a598b38f74c5eba543166cb810faaf19ac).
    lerna ERR! import You may try with --flatten to import flat history.
    lerna ERR! execute callback with error
    (node:5867) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'split' of undefined
    (node:5867) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    
  4. swernerx commented on Oct 8, 2017

    @swernerx
    ContributorAuthor

    The remaining error is the result of Lerna to not cleanly handle empty commits. These should not be in Git repositories in the first place, but still, it might make sense to handle them in some variant so that it does not throw for users importing old repositories. The following variant (inside ImportCommand.js: execute()) works well for me acting on the git error message (inside the babel transpiled code):

                if (err) {
                  const isEmpty = err.stdout.indexOf("Patch is empty.") === 0;
    
                  if (isEmpty) {
                    // Automatically skip empty commits
                    _ChildProcessUtilities2.default.execSync("git", ["am", "--skip"], _this2.execOpts);
    
                    // Reset previous error
                    err = null
                  } else {
                    // Give some context for the error message.
                    err = `Failed to apply commit ${sha}.\n${err}\n` + `Rolling back to previous HEAD (commit ${_this2.preImportHead}).\n` + `You may try with --flatten to import flat history.`;
    
                    // Abort the failed `git am` and roll back to previous HEAD.
                    _ChildProcessUtilities2.default.execSync("git", ["am", "--abort"], _this2.execOpts);
                    _ChildProcessUtilities2.default.execSync("git", ["reset", "--hard", _this2.preImportHead], _this2.execOpts);
                  }
                }
  5. swernerx commented on Oct 8, 2017

    @swernerx
    ContributorAuthor

    Added a PR to fix the detected issues in the original source code:

    #1059

  6. thecodejack commented on Oct 16, 2017

    @thecodejack

    Facing same issue. Any ETA when this gets fixed? For me --flatten also failing. It randomly fails at different commits.

    lerna info bb36013
    lerna ERR! import Failed to apply commit bb36013.
    lerna ERR! import Error: Command failed: git am -3
    lerna ERR! import fatal: Unable to create '/u/user/ux-modules/.git/index.lock': File exists.
    lerna ERR! import
    lerna ERR! import Another git process seems to be running in this repository, e.g.
    lerna ERR! import an editor opened by 'git commit'. Please make sure all processes
    lerna ERR! import are terminated then try again. If it still fails, a git process
    lerna ERR! import may have crashed in this repository earlier:
    lerna ERR! import remove the file manually to continue.
    lerna ERR! import
    lerna ERR! import Rolling back to previous HEAD (commit 299d0e6ebsa37078afaaed00415a15bae89d97575d).
    lerna ERR! import You may try with --flatten to import flat history.
    lerna ERR! execute callback with error
    (node:141145) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'split' of undefined
    
  7. azu commented on Oct 24, 2017

    @azu
    Contributor

    I've met same issue.

    lerna import throw following error when import https://github.com/textlint/gulp-textlint.

    lerna: 2.2.0 (2.4.0 also throw error)

    lerna info 07c79df
    lerna info 58b1109
    lerna info f903908
    lerna ERR! execute callback with error
    lerna ERR! execute  Failed to apply commit f903908.
    lerna ERR! execute Error: Command failed: git am -3
    lerna ERR! execute error: Failed to merge in the changes.
    lerna ERR! execute Applying: add example and test
    lerna ERR! execute Using index info to reconstruct a base tree...
    lerna ERR! execute M	packages/gulp-textlint/package.json
    lerna ERR! execute Falling back to patching base and 3-way merge...
    lerna ERR! execute Auto-merging packages/gulp-textlint/package.json
    lerna ERR! execute CONFLICT (content): Merge conflict in packages/gulp-textlint/package.json
    lerna ERR! execute Patch failed at 0001 add example and test
    lerna ERR! execute The copy of the patch that failed is found in: .git/rebase-apply/patch
    lerna ERR! execute When you have resolved this problem, run "git am --continue".
    lerna ERR! execute If you prefer to skip this patch, run "git am --skip" instead.
    lerna ERR! execute To restore the original branch and stop patching, run "git am --abort".
    lerna ERR! execute
    lerna ERR! execute Rolling back to previous HEAD (commit 6a53d00c19fb7a55c62b981c4b1196f4b9a3e0e6).
    (node:58998) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot create property 'exitCode' on string 'Failed to apply commit f903908.
    Error: Command failed: git am -3
    error: Failed to merge in the changes.
    Applying: add example and test
    Using index info to reconstruct a base tree...
    M	packages/gulp-textlint/package.json
    Falling back to patching base and 3-way merge...
    Auto-merging packages/gulp-textlint/package.json
    CONFLICT (content): Merge conflict in packages/gulp-textlint/package.json
    Patch failed at 0001 add example and test
    The copy of the patch that failed is found in: .git/rebase-apply/patch
    When you have resolved this problem, run "git am --continue".
    If you prefer to skip this patch, run "git am --skip" instead.
    To restore the original branch and stop patching, run "git am --abort".
    
    Rolling back to previous HEAD (commit 6a53d00c19fb7a55c62b981c4b1196f4b9a3e0e6).'
    (node:58998) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    

    Edit(2017-10-24):

    I've used --flatten and success imports.

  8. evocateur commented on Oct 27, 2017

    @evocateur
    Member

    Thanks for your patience, I'm looking at the PR now.

  9. webernir commented on Oct 29, 2017

    @webernir

    Thank you @azu @swernerx
    using --flatten worked for me as well.

  10. vzaidman commented on Dec 5, 2017

    @vzaidman

    --flatten works indeed but as someone who uses "git flow" we NEED our merging history to not be ignored for all the packages we import.

    #615 solves it much more nicely.

  11. vzaidman commented on Dec 5, 2017

    @vzaidman

    i end up using "git subtree" as follows:

    git subtree add -P packages/some-package ../src-to-some-package master
    

    image

  12. stale commented on Dec 27, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  13. lock commented on Apr 3, 2019

    @lock

    This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  14. locked as resolved and limited conversation to collaborators on Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions