question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pull crashes Node, cannot be caught using try-catch

See original GitHub issue

Hey, pull brings Node down for me in the TypeScript repro below:

import * as git from 'isomorphic-git';
import * as fs from 'fs-extra';
import * as readline from 'readline';

void async function() {
  console.log('Removing…');
  await fs.remove('junk');
  console.log('Removed.');

  let errored = false;

  try {
    console.log('Cloning…');
    await git.clone({ fs, dir: 'junk', ref: 'master', url: 'https://github.com/TomasHubelbauer/bloggo.git' });
    console.log('Cloned.');
  } catch (error) {
    console.log('Failed to clone:', error);
    errored = true;
  }

  try {
    console.log('Pulling…');
    await git.pull({ fs, dir: 'junk', ref: 'master' });
    console.log('Pulled.');
  } catch (error) {
    console.log('Failed to pull:', error);
    errored = true;
  }

  // Added to prove the process will end without any user interaction
  !errored && await new Promise(resolve => {
    readline.createInterface(process.stdin, process.stdout).question('Blocking…', (answer) => resolve(answer));
  });
}()

Here’s the full output:

Removing…
Removed.
Cloning…
Cloned.
Pulling…
Using ref=master

I am using Node v9.4.0, Isomorphic Git version "0.9.0" and FS Extra version "5.0.0".

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wmhiltoncommented, Jun 4, 2018

Since this is (hopefully?) a super rare edge case with corrupt git repositories, I’m going to close it and hope it doesn’t happen again. 😁 But if it does, we’ll have to address it because it was quite a serious crash.

1reaction
wmhiltoncommented, Mar 9, 2018

Oooh, this is really interesting. I’m not using TypeScript, but can get the same error using plain JS and node v9.6.1:

const git = require('isomorphic-git');
const fs = require('fs-extra');
const readline = require('readline');

void async function() {
  console.log('Removing…');
  await fs.remove('junk');
  console.log('Removed.');

  let errored = false;

  try {
    console.log('Cloning…');
    await git.clone({ fs, dir: 'junk', ref: 'master', url: 'https://github.com/TomasHubelbauer/bloggo.git' });
    console.log('Cloned.');
  } catch (error) {
    console.log('Failed to clone:', error);
    errored = true;
  }

  try {
    console.log('Pulling…');
    await git.pull({ fs, dir: 'junk', ref: 'master' });
    console.log('Pulled.');
  } catch (error) {
    console.log('Failed to pull:', error);
    errored = true;
  }

  // Added to prove the process will end without any user interaction
  !errored && await new Promise(resolve => {
    readline.createInterface(process.stdin, process.stdout).question('Blocking…', (answer) => resolve(answer));
  });
}()

Here is the output… interestingly I get an error during clone before it crashes:

> node index.js
Removing…
Removed.
Cloning…
Failed to clone: Error: Unexpected object type commit found in tree for 'junk'
    at writeTreeToDisk (E:\git\isomorphic-git\isomorphic-git\bugs\86\node_modules\isomorphic-git\dist\for-node\isomorphic-git\commands.js:384:15)
    at <anonymous>
Pulling…
Using ref=master

BUT! if I change the url from https://github.com/TomasHubelbauer/bloggo.git to https://github.com/isomorphic-git/isomorphic-git.git then it doesn’t crash. And (if anyone wonders) cloning bloggo with canonical git does not crash.

The plot thickens! If I clone greenkeeper/initial instead of master it still crashes… but I don’t get the Failed to clone: Error: Unexpected object type commit found in tree for 'junk'. (In case I need the commits to track this down… greenkeeper/initial is currently at a96fc839d667e7c03de7cc98dc0d5a9530bd5bbc and master is currently at 159af9ed895d49d09af27a6c6b0457961cde3042.)

It’s also not the use of fs-extra which was my first thought. Does the exact same behavior with regular fs.

Investigation status: To Be Continued…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Try/Catch and Domains for Error Handling in ...
Looking at JugglingDB, and trying to connect to a non-existent mysql server on my laptop, I do get ECONNREFUSED , but it's only...
Read more >
When Try-Catch Doesn't Catch Errors in Node.js |
To demonstrate this problem, I will use Node.js streams: Stream is a structure that allows users to read/write data sequentially from/to it.
Read more >
Exceptions and debugging - Advanced R. - Hadley Wickham
Condition handling tools, like withCallingHandlers() , tryCatch() , and try() allow you to take specific actions when a condition occurs. For example, if...
Read more >
A Comprehensive Guide To Error Handling In Node.js
When you throw an error, it becomes an exception and needs to be caught somewhere up the stack using a try/catch block.
Read more >
Error handling with promises - The Modern JavaScript Tutorial
catch at the end to handle errors in all of them. In a regular try..catch we can analyze the error and maybe rethrow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found