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

mkfile error throws instead of callback #6

Description

@maritz

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions