2017-05-22 12 views
0

GitNode라는 Node.JS 라이브러리를 사용하고 있습니다. 중요하지는 않지만 기본적으로 Node.JS의 git 명령 용 API입니다.Node.JS에서 오류 또는 예외를 출력하지 못합니다.

기존 저장소에 새 분기를 만드는 것이 목적 인 코드 조각이 있습니다. 코드를 실행 한 후에 저장소가 생성되지 않는다는 것을 알고 있으며 올바르게 작동하지 않는다는 것도 알고 있습니다.

var Git = require("nodegit"); 

var getMostRecentCommit = function(repository) { 
    return repository.getBranchCommit("master"); 
}; 

var makeBranch = function(respository) { 
    console.log("in here1") 
    repository.createBranch("tester", getMostRecentCommit(repository)).then(
     function(reference) { 
      console.log("good")},    // if it works 
     function(reasonForFailure) { 
      console.log("bad_error")})   // createBranch has error case 
     .catch(function(reasonForFailure) { 
      console.log("bad_catch")});   // if the error function fails, I also have a catch statement 
}; 


Git.Repository.open("../test_repo") 
    .then(makeBranch); 

내 오류를 찾는 희망 catch 문을 많이 배치했습니다

내 코드의 전체입니다. 그러나 나는 아무것도 출력하지 않는 것 같습니다. 문구 "Bad_error"또는 "Bad_catch"가 출력되지 않습니다.

코드가 손상되어 createBranch가 작동하지 않는다는 것을 알고 있습니다. repository.createBranch을 호출 한 후 실행해야하는 코드를 테스트했지만, createBranch가 호출되기 전에 아무 것도 실행되지 않습니다. 이는 CreateBranch가 문제임을 나타냅니다.

왜 내 오류가 발견되지 않습니까?

편집

내가 코드를 수정했습니다과 오류를 출력 (아래 답변을 참조)하지만 내 다른 예외/오류 문이 작동하는 데 실패 난 아직도 왜 궁금하네요.

답변

0

그래서, 난 그냥 내 Repository.open() 함수에 catch 문을 추가했다 here

에 문제가 감사의 일부를 알아 냈어. 누군가가 호기심 경우

var makeBranch = function(respository) { 
    console.log("in here1") 
    repository.createBranch("tester", getMostRecentCommit(repository)).then(
     function(reference) { 
      console.log("good")},    
     function(reasonForFailure) { 
      console.log("bad_error")})   
     .catch(function(reasonForFailure) { 
      console.log("bad_catch")});   
}; 


Git.Repository.open("../test_repo") 
    .then(makeBranch).catch(
    function(reasonForFailure) {console.log("bad")}); // This Works 

, 나는 변수 respository 대신 repository 전달되었다 밝혀 : P

그리고이 출력됩니다 bad. 그래서 좋았어. 나는 아직도 왜 이것이 효과가 있었는지는 잘 모르겠지만 다른 catch 문은 그렇지 않았다. 나는 여전히 좋은 대답이나 설명을 찾고있다.