-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stdin): throw errors on invalid input
replicates behavior prior to addition of stdin feature
- Loading branch information
1 parent
1891622
commit 1cad9fe
Showing
4 changed files
with
311 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import isPathValid from 'is-valid-path' | ||
|
||
const INVALID_PATH_ERROR = 'Invalid path' | ||
const INVALID_JSON_PATH_ERROR = 'Not a json file' | ||
export const INVALID_PATH_ERROR = | ||
'node-jq: invalid path argument supplied (not a valid path)' | ||
export const INVALID_JSON_PATH_ERROR = | ||
'node-jq: invalid path argument supplied (not a .json file)' | ||
|
||
export const isJSONPath = (path) => { | ||
export const isJSONPath = path => { | ||
return /\.json$/.test(path) | ||
} | ||
|
||
export const validateJSONPath = (JSONFile) => { | ||
if (!isPathValid(JSONFile)) { | ||
throw (Error(INVALID_PATH_ERROR)) | ||
export const validateJSONPath = path => { | ||
if (!isPathValid(path)) { | ||
throw new Error(`${INVALID_PATH_ERROR}: "${path}"`) | ||
} | ||
|
||
if (!isJSONPath(JSONFile)) { | ||
throw (Error(INVALID_JSON_PATH_ERROR)) | ||
if (!isJSONPath(path)) { | ||
throw new Error(`${INVALID_JSON_PATH_ERROR}: "${path === '' ? '' : path}"`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.