From ac4a9e3d86d39a5b979dbdda44376be85b91ece7 Mon Sep 17 00:00:00 2001 From: Ziggy Jonsson Date: Tue, 7 Mar 2017 16:45:29 -0500 Subject: [PATCH] Move props.path check below class init (#55) `self.error` is not available until the prototype is available PR-URL: https://github.com/npm/fstream/pull/55 Credit: @ZJONSSON Reviewed-By: @zkat --- lib/reader.js | 8 ++++---- lib/writer.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/reader.js b/lib/reader.js index 876021f..be4f570 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -21,10 +21,6 @@ function Reader (props, currentStat) { props = { path: props } } - if (!props.path) { - self.error('Must provide a path', null, true) - } - // polymorphism. // call fstream.Reader(dir) to get a DirReader object, etc. // Note that, unlike in the Writer case, ProxyReader is going @@ -85,6 +81,10 @@ function Reader (props, currentStat) { Abstract.call(self) + if (!props.path) { + self.error('Must provide a path', null, true) + } + self.readable = true self.writable = false diff --git a/lib/writer.js b/lib/writer.js index ca3396b..140e449 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -30,8 +30,6 @@ function Writer (props, current) { props = { path: props } } - if (!props.path) self.error('Must provide a path', null, true) - // polymorphism. // call fstream.Writer(dir) to get a DirWriter object, etc. var type = getType(props) @@ -61,6 +59,8 @@ function Writer (props, current) { Abstract.call(self) + if (!props.path) self.error('Must provide a path', null, true) + // props is what we want to set. // set some convenience properties as well. self.type = props.type