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...
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
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);
});