Console.log not showing in second layer of node promise












0















I'm creating a custom CHANGELOG generator based on git commits using nodegit (I didn't quite like the existing similar projects, and it's a pretty simple tool to make, in theory at least).



My problem right now is that I can't seem to get the console.log to show any output when it's in the second layer of promises.



This code shows the first console.log entry, but the second one disappears into cyberspace. It doesn't show any errors or anything, it just doesn't appear in the console.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
});
});
});


And just to verify that the problem isn't in the getTagByName function, the below code works just fine and outputs THIS SHOWS, so it's something related to putting the logging function in the second layer of the promises.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.getTagByName('v0.0.1').then(function (tag) {
console.log("THIS SHOWS");
});
});


I've tried a couple different versions of the same code by the way, e.g. using return repo_handle.Tag.list(repo_handle) and then(tag_list), but the results were the same.



As far as I can tell the code isn't actually having any errors or anything, the code seems to work just fine since I'm not getting any errors, but then again if console.log isn't working properly then it could just be the case that it isn't showing me the errors either...










share|improve this question























  • then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

    – Liam
    Nov 22 '18 at 11:16








  • 1





    offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

    – William Chong
    Nov 22 '18 at 11:18











  • @Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

    – Simon Hyll
    Nov 22 '18 at 11:26











  • @William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

    – Simon Hyll
    Nov 22 '18 at 11:28











  • off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

    – Liam
    Nov 22 '18 at 11:33
















0















I'm creating a custom CHANGELOG generator based on git commits using nodegit (I didn't quite like the existing similar projects, and it's a pretty simple tool to make, in theory at least).



My problem right now is that I can't seem to get the console.log to show any output when it's in the second layer of promises.



This code shows the first console.log entry, but the second one disappears into cyberspace. It doesn't show any errors or anything, it just doesn't appear in the console.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
});
});
});


And just to verify that the problem isn't in the getTagByName function, the below code works just fine and outputs THIS SHOWS, so it's something related to putting the logging function in the second layer of the promises.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.getTagByName('v0.0.1').then(function (tag) {
console.log("THIS SHOWS");
});
});


I've tried a couple different versions of the same code by the way, e.g. using return repo_handle.Tag.list(repo_handle) and then(tag_list), but the results were the same.



As far as I can tell the code isn't actually having any errors or anything, the code seems to work just fine since I'm not getting any errors, but then again if console.log isn't working properly then it could just be the case that it isn't showing me the errors either...










share|improve this question























  • then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

    – Liam
    Nov 22 '18 at 11:16








  • 1





    offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

    – William Chong
    Nov 22 '18 at 11:18











  • @Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

    – Simon Hyll
    Nov 22 '18 at 11:26











  • @William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

    – Simon Hyll
    Nov 22 '18 at 11:28











  • off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

    – Liam
    Nov 22 '18 at 11:33














0












0








0








I'm creating a custom CHANGELOG generator based on git commits using nodegit (I didn't quite like the existing similar projects, and it's a pretty simple tool to make, in theory at least).



My problem right now is that I can't seem to get the console.log to show any output when it's in the second layer of promises.



This code shows the first console.log entry, but the second one disappears into cyberspace. It doesn't show any errors or anything, it just doesn't appear in the console.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
});
});
});


And just to verify that the problem isn't in the getTagByName function, the below code works just fine and outputs THIS SHOWS, so it's something related to putting the logging function in the second layer of the promises.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.getTagByName('v0.0.1').then(function (tag) {
console.log("THIS SHOWS");
});
});


I've tried a couple different versions of the same code by the way, e.g. using return repo_handle.Tag.list(repo_handle) and then(tag_list), but the results were the same.



As far as I can tell the code isn't actually having any errors or anything, the code seems to work just fine since I'm not getting any errors, but then again if console.log isn't working properly then it could just be the case that it isn't showing me the errors either...










share|improve this question














I'm creating a custom CHANGELOG generator based on git commits using nodegit (I didn't quite like the existing similar projects, and it's a pretty simple tool to make, in theory at least).



My problem right now is that I can't seem to get the console.log to show any output when it's in the second layer of promises.



This code shows the first console.log entry, but the second one disappears into cyberspace. It doesn't show any errors or anything, it just doesn't appear in the console.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
});
});
});


And just to verify that the problem isn't in the getTagByName function, the below code works just fine and outputs THIS SHOWS, so it's something related to putting the logging function in the second layer of the promises.



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.getTagByName('v0.0.1').then(function (tag) {
console.log("THIS SHOWS");
});
});


I've tried a couple different versions of the same code by the way, e.g. using return repo_handle.Tag.list(repo_handle) and then(tag_list), but the results were the same.



As far as I can tell the code isn't actually having any errors or anything, the code seems to work just fine since I'm not getting any errors, but then again if console.log isn't working properly then it could just be the case that it isn't showing me the errors either...







javascript node.js nodegit






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 11:13









Simon HyllSimon Hyll

94311023




94311023













  • then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

    – Liam
    Nov 22 '18 at 11:16








  • 1





    offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

    – William Chong
    Nov 22 '18 at 11:18











  • @Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

    – Simon Hyll
    Nov 22 '18 at 11:26











  • @William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

    – Simon Hyll
    Nov 22 '18 at 11:28











  • off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

    – Liam
    Nov 22 '18 at 11:33



















  • then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

    – Liam
    Nov 22 '18 at 11:16








  • 1





    offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

    – William Chong
    Nov 22 '18 at 11:18











  • @Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

    – Simon Hyll
    Nov 22 '18 at 11:26











  • @William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

    – Simon Hyll
    Nov 22 '18 at 11:28











  • off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

    – Liam
    Nov 22 '18 at 11:33

















then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

– Liam
Nov 22 '18 at 11:16







then only fires if your promise is successful, so your promise isn't successful. You don't actually show what getTagByName does so beyond that we can't help

– Liam
Nov 22 '18 at 11:16






1




1





offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

– William Chong
Nov 22 '18 at 11:18





offtopic: nested .then() is anti-pattern, they are supposed to be chained, not forming another callback hell

– William Chong
Nov 22 '18 at 11:18













@Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

– Simon Hyll
Nov 22 '18 at 11:26





@Liam getTagByName is part of the nodegit API, so if you wanna see it you'd have to head on over there. It's an async function that returns a Tag object.

– Simon Hyll
Nov 22 '18 at 11:26













@William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

– Simon Hyll
Nov 22 '18 at 11:28





@William Chong Now that you mention it I know I've read about that before and actually know about it... I'm gonna pretend this was just test code that just needed to work, not be good ^^

– Simon Hyll
Nov 22 '18 at 11:28













off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

– Liam
Nov 22 '18 at 11:33





off topic, did you know you surname means "ugly" in welsh? Not to make any comment on your character or person but thought you might find it interesting :)

– Liam
Nov 22 '18 at 11:33












1 Answer
1






active

oldest

votes


















2














It probably means that repo_handle.getTagByName('v0.0.1').then(function (tag) { never starts. Try something like this:



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});


console.log itself has nothing to to with the depth of promise nesting



Update from asker



For those that find this later, the actual problem turned out to be that repo_handle.Tag was undefined, and I found it thanks to adding a catch for the error, hence accepting this answer.



The new updated code that works is as follows:



let nodegit = require('nodegit');
let path = require('path');

var repo_root = path.resolve(__dirname, './.git');
let repo = null;

nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});





share|improve this answer


























  • I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

    – Simon Hyll
    Nov 22 '18 at 11:24













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429723%2fconsole-log-not-showing-in-second-layer-of-node-promise%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














It probably means that repo_handle.getTagByName('v0.0.1').then(function (tag) { never starts. Try something like this:



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});


console.log itself has nothing to to with the depth of promise nesting



Update from asker



For those that find this later, the actual problem turned out to be that repo_handle.Tag was undefined, and I found it thanks to adding a catch for the error, hence accepting this answer.



The new updated code that works is as follows:



let nodegit = require('nodegit');
let path = require('path');

var repo_root = path.resolve(__dirname, './.git');
let repo = null;

nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});





share|improve this answer


























  • I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

    – Simon Hyll
    Nov 22 '18 at 11:24


















2














It probably means that repo_handle.getTagByName('v0.0.1').then(function (tag) { never starts. Try something like this:



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});


console.log itself has nothing to to with the depth of promise nesting



Update from asker



For those that find this later, the actual problem turned out to be that repo_handle.Tag was undefined, and I found it thanks to adding a catch for the error, hence accepting this answer.



The new updated code that works is as follows:



let nodegit = require('nodegit');
let path = require('path');

var repo_root = path.resolve(__dirname, './.git');
let repo = null;

nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});





share|improve this answer


























  • I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

    – Simon Hyll
    Nov 22 '18 at 11:24
















2












2








2







It probably means that repo_handle.getTagByName('v0.0.1').then(function (tag) { never starts. Try something like this:



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});


console.log itself has nothing to to with the depth of promise nesting



Update from asker



For those that find this later, the actual problem turned out to be that repo_handle.Tag was undefined, and I found it thanks to adding a catch for the error, hence accepting this answer.



The new updated code that works is as follows:



let nodegit = require('nodegit');
let path = require('path');

var repo_root = path.resolve(__dirname, './.git');
let repo = null;

nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});





share|improve this answer















It probably means that repo_handle.getTagByName('v0.0.1').then(function (tag) { never starts. Try something like this:



git.Repository.open(repo_root).then(function (repo_handle) {
repo_handle.Tag.list(repo_handle).then(function (tag_list) {
console.log("THIS SHOWS"); // <--- Shows
repo_handle.getTagByName(tag_list[0]).then(function (tag) {
console.log("THIS DOES NOT"); // <--- Doesn't show
}).catch(error => {
console.log("gotcha! ", error);
});
});
});


console.log itself has nothing to to with the depth of promise nesting



Update from asker



For those that find this later, the actual problem turned out to be that repo_handle.Tag was undefined, and I found it thanks to adding a catch for the error, hence accepting this answer.



The new updated code that works is as follows:



let nodegit = require('nodegit');
let path = require('path');

var repo_root = path.resolve(__dirname, './.git');
let repo = null;

nodegit.Repository.open(repo_root)
.then(function (repo_handle) {
repo = repo_handle;
return nodegit.Tag.list(repo_handle);
})
.then(function (tag_list) {
return repo.getTagByName(tag_list[0]);
})
.then(function (tag) {
console.log(tag.message());
})
.catch(function (e) {
console.error(e);
});






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 12:42









Simon Hyll

94311023




94311023










answered Nov 22 '18 at 11:16









Anton PastukhovAnton Pastukhov

1978




1978













  • I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

    – Simon Hyll
    Nov 22 '18 at 11:24





















  • I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

    – Simon Hyll
    Nov 22 '18 at 11:24



















I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

– Simon Hyll
Nov 22 '18 at 11:24







I feel so stupid for not thinking of using a .catch for errors... It turns out there's some problem with repo_handle.Tag.list being undefined, even if I swear to Jebus that there are no errors in the code in that part since I used that part like 30 minutes ago fully functional... Will accept your answer since it lead to the solution, thanks!

– Simon Hyll
Nov 22 '18 at 11:24






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429723%2fconsole-log-not-showing-in-second-layer-of-node-promise%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith