Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

mkfile error throws instead of callback #6

Open
maritz opened this issue Feb 7, 2013 · 0 comments
Open

mkfile error throws instead of callback #6

maritz opened this issue Feb 7, 2013 · 0 comments

Comments

@maritz
Copy link

maritz commented Feb 7, 2013

In localfs.js#L343 there is an issue where the callback is called with an error but no meta object.

In the callback error case meta.stream is accessed. Since meta is undefined, this throws, making the entire point of a callback for the error case meaningless. (and as it so happens, this crashes my c9 install)

var callback = function (err, meta) {
            if (called) {
                if (err) {
                    if (meta.stream) meta.stream.emit("error", err);
                    else console.error(err.stack);
                }
                else if (meta.stream) meta.stream.emit("saved");
                return;
            }
            called = true;
            return realCallback.apply(this, arguments);
        };

        if (options.stream && !options.stream.readable) {
            return callback(new TypeError("options.stream must be readable."));
        }

Changing that like the following should fix this.

var callback = function (err, meta) {
            if (called) {
                if (err) {
                    if (meta && meta.stream) meta.stream.emit("error", err);
                    else console.error(err.stack);
                }
                else if (meta && meta.stream) meta.stream.emit("saved");
                return;
            }
            called = true;
            return realCallback.apply(this, arguments);
        };

        if (options.stream && !options.stream.readable) {
            return callback(new TypeError("options.stream must be readable."));
        }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant