Skip to content

Commit

Permalink
suppress error messages by default
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbeatty committed Oct 18, 2016
1 parent 6349be8 commit 3c89132
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ 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
13 changes: 7 additions & 6 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,13 @@
"devDependencies": {
"babel": "5.8.23",
"coveralls": "^2.11.9",
"eslint": "3.7.1",
"lab": "5.17.0",
"semver": "5.0.3",
"semver": "5.3.0",
"should": "7.1.0",
"sinon": "1.16.1",
"standard": "5.3.0",
"standard-markdown": "^1.1.1"
"sinon": "1.17.6",
"standard": "8.4.0",
"standard-markdown": "2.2.0"
},
"dependencies": {}
}
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

0 comments on commit 3c89132

Please sign in to comment.