Skip to content

Commit

Permalink
include env key in error and logs when value is too large (#159)
Browse files Browse the repository at this point in the history
* include env key in error and logs when value is too large

* code review fix: consistent log formatting
  • Loading branch information
lszucs authored Feb 7, 2019
1 parent 41ea1b6 commit a9fc969
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cli/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"errors"
"fmt"
"io/ioutil"
"os"

Expand Down Expand Up @@ -40,9 +41,9 @@ func validateEnv(key, value string, envList []models.EnvironmentItemModel) (stri
if configs.EnvBytesLimitInKB > 0 {
if valueSizeInBytes > configs.EnvBytesLimitInKB*1024 {
valueSizeInKB := ((float64)(valueSizeInBytes)) / 1024.0
log.Warnf("environment value (%s...) too large", value[0:100])
log.Warnf("environment var (%s) value (%s...) too large", key, value[0:100])
log.Warnf("environment value size (%#v KB) - max allowed size: %#v KB", valueSizeInKB, (float64)(configs.EnvBytesLimitInKB))
return "environment value too large - rejected", nil
return fmt.Sprintf("environment var (%s) value too large - rejected", key), nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func TestValidateEnv(t *testing.T) {

valValue, err = validateEnv("key", str21Kbytes, envs)
require.NoError(t, err)
require.Equal(t, "environment value too large - rejected", valValue)
require.Equal(t, "environment var (key) value too large - rejected", valValue)
}

0 comments on commit a9fc969

Please sign in to comment.