Skip to content

coerce send too many (useless) argument  #338

Description

@A-312

Depending of the README, coerce should be have only one argument but we send 3 arguments, coerce: function(val) {. I will simplify the script for #313 and I remove the 2th and 3th arg.

convict.addFormat({
  name: 'float-percent',
  validate: function(val) {
    if (val !== 0 && (!val || val > 1 || val < 0)) {
      throw new Error('must be a float between 0 and 1, inclusive');
    }
  },
  coerce: function(val) {
    console.log(arguments, +val);
    return parseFloat(val, 10);
  }
});

Current log :

[Arguments] {                                                       
  '0': '0.8',                                                       
  '1': {                                                            
    getArgs: [Function: getArgs],                                   
    getEnv: [Function: getEnv],                                     
    getProperties: [Function: getProperties],                       
    toString: [Function: toString],                                 
    getSchema: [Function: getSchema],                               
    getSchemaString: [Function: getSchemaString],                   
    get: [Function: get],                                           
    default: [Function: default],                                   
    reset: [Function: reset],                                       
    has: [Function: has],                                           
    set: [Function: set],                                           
    load: [Function: load],                                         
    loadFile: [Function: loadFile],                                 
    validate: [Function: validate],                                 
    _def: { ip: [Object], port: [Object], percent: [Object] },      
    _schema: { properties: [Object] },                              
    _env: { IP_ADDRESS: [Array], PORT: [Array], percent: [Array] }, 
    _argv: {},                                                      
    _sensitive: Set {},                                             
    _instance: { ip: '127.0.0.1', port: 8080, percent: 0.1, ok: 8 } 
  },                                                                
  '2': 'percent'                                                    
} 0.8                                                               

Expected :

[Arguments] {                                                       
  '0': '0.8'                                               
} 0.8   

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions