isomorphic-git: GitPackIndex cannot read 'slice' of null

Using node:

const fs = require("fs")
const git = require("isomorphic-git")

git.log({ fs, dir: "/my-project", depth: 1, ref: "<sha>" }).then(res => console.log(res))

errors with:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'slice' of null
    at GitPackIndex.readSlice (/my-project/node_modules/isomorphic-git/index.cjs:2666:35)

This appears to be coming from: https://github.com/isomorphic-git/isomorphic-git/blob/main/src/models/GitPackIndex.js#L297

I was not on the latest, but I tried upgrading and it’s still happening.

What is strange is that its pretty intermittent - its only happening in my ci, and I can’t seem to repro locally. Any idea what might be causing this? Perhaps some issue with the git repo? I tried a git fsck already but it didn’t show up any issues.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 13
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I’m also experiencing this.

As a start, it would be useful to not silently supress the error encountered on the file system read.

Second, there is a check for !this.pack right above the erroring line that should prevent the error and instead throw a more human-readable error: 'Tried to read from a GitPackIndex with no packfile loaded into memory', however this does not work because the await is missing and this.pack is a promise https://github.com/isomorphic-git/isomorphic-git/blob/2e32ed29c92e2bffefa898126924c3cd4506bfa5/src/models/GitPackIndex.js#L292-L297

Third, however, requiring the entire file to be read into memory seems like a larger underlying issue. I am working with pack files of ~40gb (more than my system RAM). As a comparison, nodegit was able to handle this without a sweat. Limiting the max pack size in the git config is a meh-okay workaround.

The workaround is to configure git so it limits the size of the pack files it creates locally. This is done using the pack.packSizeLimit config setting.

git config pack.packSizeLimit 1g
git gc

You can find information about this setting here: https://www.git-scm.com/docs/git-pack-objects

The real issue is that there is an IO error, but isomorphic-git is suppressing it. The problem starts at this line:

const raw = (await this.pack).slice(start);

At this point, this.pack is a promise to read the file. If there’s an IO error, the fs implementation returns null (see https://github.com/isomorphic-git/isomorphic-git/blob/162827ae4261495a56ef8598e3153868016296c2/src/models/FileSystem.js#L109). At this point, the call to slice fails. So we really don’t know what the real error is.

For anyone who wants to find out, remove the catch in the read method and let’s see what’s going on.