Skip to content

Commit

Permalink
Issue #168: Need better error message when using invalid character wh…
Browse files Browse the repository at this point in the history
…en creating an environment variable name (#171)

Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst authored Jan 18, 2024
1 parent 10f3f1f commit 535e3dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/commands/env/create/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = async function action (params) {
let { access_token: token, stagingAPI: _staging } = config
let client = require('@begin/api')
let error = require('../errors')(params)
let looseName = /^[a-zA-Z_][a-zA-Z0-9_]+$/

// Environment (required)
let env = args.env || args.e
Expand All @@ -21,6 +22,9 @@ module.exports = async function action (params) {
if (!name || name === true) {
return error('no_name')
}
if (!looseName.test(name) || name.length > 64) {
return error('invalid_varname')
}
name = name.toUpperCase()

// Value (required)
Expand Down
1 change: 1 addition & 0 deletions src/commands/env/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function error (params) {
no_appid: 'App ID not found, please run with -a or --appID',
no_env: 'Environment ID not found, please run with -e or --envID',
no_name: 'Variable name not found, please run with -n or --name',
invalid_varname: 'Environment variable names can consist of up to 64 characters. The name can contain upper and lowercase letters, numbers, and underscores (_), but it must start with a letter or underscore.',
no_value: 'Variable value not found, please run with -v or --value',
create_fail: 'Failed to create environment variable',
destroy_fail: 'Failed to destroy environment variable',
Expand Down

0 comments on commit 535e3dc

Please sign in to comment.