natevw / fatfs

Standalone FAT16/FAT32 filesystem implementation in JavaScript
47 stars 13 forks source link

emit an 'error' event if init() fails #25

Closed zvin closed 7 years ago

zvin commented 7 years ago

The 'error' event is not emitted when init fails.

Here is a simple test case:

const fatfs = require('fatfs')

const fat = fatfs.createFileSystem({
    sectorSize: 512,
    numSectors: 1000,
    readSectors: function(sector, dest, callback) {
        // read always returns zeros
        callback(null, Buffer.alloc(dest.length));
    },
    writeSectors: function(sector, data, callback) {
        callback(null, data.length)
    }
});

fat.on('error', function(err) {
    console.log('err', err)
})
fat.on('ready', function() {
    console.log('ready')
})

I would expect this code to output 'err' followed by the actual error. Instead it just prints the error and exits.

This PR fixes it.

natevw commented 7 years ago

Thanks, good catch! Published as fatfs@0.10.6 on npm.

zvin commented 7 years ago

Thank you for the quick merge.