Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress error messages by default #154

Merged
merged 4 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: node_js

node_js:
- 0.10
- 0.12
- 4
- 5
- 6
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ _Alias: `load`_

### Options

#### Silent
#### Verbose

Default: `false`

Dotenv outputs a warning to your console if missing a `.env` file. Suppress
this warning using silent.
All errors are suppressed by default. Set this to `true` for more logging.

```js
require('dotenv').config({silent: true})
require('dotenv').config({verbose: true})
```

#### Path
Expand Down
12 changes: 6 additions & 6 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module.exports = {
config: function (options) {
var path = '.env'
var encoding = 'utf8'
var silent = false
var verbose = false

if (options) {
if (options.silent) {
silent = options.silent
if (options.verbose) {
verbose = options.verbose
}
if (options.path) {
path = options.path
Expand All @@ -35,8 +35,8 @@ module.exports = {

return parsedObj
} catch (e) {
if (!silent) {
console.error(e)
if (verbose) {
console.error('dotenv failed to parse and/or populate:' + e.message)
}
return false
}
Expand All @@ -63,7 +63,7 @@ module.exports = {

// expand newlines in quoted values
var len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '\"' && value.charAt(len - 1) === '\"') {
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
value = value.replace(/\\n/gm, '\n')
}

Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"scripts": {
"pretest": "npm run lint",
"test": "lab test/* -r lcov | coveralls",
"posttest": "npm run lint",
"postlint": "npm run lint-md",
"lint": "standard",
"postlint": "npm run lint-md",
"lint-md": "standard-markdown"
},
"repository": {
Expand All @@ -29,12 +29,15 @@
"devDependencies": {
"babel": "5.8.23",
"coveralls": "^2.11.9",
"lab": "5.17.0",
"semver": "5.0.3",
"should": "7.1.0",
"sinon": "1.16.1",
"standard": "5.3.0",
"standard-markdown": "^1.1.1"
"lab": "11.1.0",
"semver": "5.3.0",
"should": "11.1.1",
"sinon": "1.17.6",
"standard": "8.4.0",
"standard-markdown": "2.2.0"
},
"dependencies": {}
"dependencies": {},
"engines": {
"node": ">=4.6.0"
}
}
4 changes: 2 additions & 2 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

require('should')
var child_process = require('child_process')
var cp = require('child_process')
var semver = require('semver')
// var sinon = require('sinon')
var Lab = require('lab')
Expand All @@ -21,7 +21,7 @@ describe('config', function () {
return done()
}

child_process.exec(
cp.exec(
nodeBinary + ' -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env',
function (err, stdout, stderr) {
if (err) {
Expand Down
12 changes: 6 additions & 6 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ describe('dotenv', function () {
readFileSyncStub.throws()

dotenv.config().should.eql(false)
errorStub.callCount.should.eql(1)
errorStub.called.should.be.false // because verbose is off
done()
})

it('takes option for silencing errors', function (done) {
it('takes option for exposing errors', function (done) {
var errorStub = s.stub(console, 'error')
readFileSyncStub.throws()

dotenv.config({silent: true}).should.eql(false)
errorStub.called.should.be.false
dotenv.config({verbose: true}).should.eql(false)
errorStub.callCount.should.eql(1)
done()
})
})
Expand Down Expand Up @@ -157,8 +157,8 @@ describe('dotenv', function () {
})

it('retains inner quotes', function (done) {
parsed.RETAIN_INNER_QUOTES.should.eql('{\"foo\": \"bar\"}')
parsed.RETAIN_INNER_QUOTES_AS_STRING.should.eql('{\"foo\": \"bar\"}')
parsed.RETAIN_INNER_QUOTES.should.eql('{"foo": "bar"}')
parsed.RETAIN_INNER_QUOTES_AS_STRING.should.eql('{"foo": "bar"}')
done()
})

Expand Down