How to use the ono.syntax function in ono

To help you get started, we’ve selected a few ono examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github APIDevTools / json-schema-ref-parser / lib / read.js View on Github external
if (promise) {
      return promise
        .then(function(data) {
          // Update the $ref with the parsed file contents
          var value = parse(data, $ref.path, options);
          $ref.setValue(value, options);

          return {
            $ref: $ref,
            cached: false
          };
        });
    }
    else {
      return Promise.reject(ono.syntax('Unable to resolve $ref pointer "%s"', $ref.path));
    }
  }
  catch (e) {
    return Promise.reject(e);
  }
}
github APIDevTools / json-schema-ref-parser / lib / parse.js View on Github external
}
  catch (e) {
    var ext = util.path.extname(path);
    if (options.allow.unknown && ['.json', '.yaml', '.yml'].indexOf(ext) === -1) {
      // It's not a YAML or JSON file, and unknown formats are allowed,
      // so ignore the parsing error and just return the raw data
      util.debug('    Unknown file format. Not parsed.');
      parsed = data;
    }
    else {
      throw ono.syntax(e, 'Error parsing "%s"', path);
    }
  }

  if (isEmpty(parsed) && !options.allow.empty) {
    throw ono.syntax('Error parsing "%s". \nParsed value is empty', path);
  }

  return parsed;
}
github APIDevTools / json-schema-ref-parser / lib / parse.js View on Github external
util.debug('    Parsed successfully');
    }
    else {
      parsed = data;
    }
  }
  catch (e) {
    var ext = util.path.extname(path);
    if (options.allow.unknown && ['.json', '.yaml', '.yml'].indexOf(ext) === -1) {
      // It's not a YAML or JSON file, and unknown formats are allowed,
      // so ignore the parsing error and just return the raw data
      util.debug('    Unknown file format. Not parsed.');
      parsed = data;
    }
    else {
      throw ono.syntax(e, 'Error parsing "%s"', path);
    }
  }

  if (isEmpty(parsed) && !options.allow.empty) {
    throw ono.syntax('Error parsing "%s". \nParsed value is empty', path);
  }

  return parsed;
}
github APIDevTools / json-schema-ref-parser / lib / core / parse-file.js View on Github external
function onError(err) {
      if (err) {
        err = err instanceof Error ? err : new Error(err);
        reject(ono.syntax(err, 'Error parsing %s', file.url));
      }
      else {
        reject(ono.syntax('Unable to parse %s', file.url));
      }
    }
  });
github APIDevTools / json-schema-ref-parser / lib / read.js View on Github external
function onError(err) {
      if (err && !(err instanceof SyntaxError)) {
        reject(err);
      }
      reject(ono.syntax('Unable to resolve $ref pointer "%s"', path));
    }
  });
github APIDevTools / json-schema-ref-parser / lib / pointer.js View on Github external
function setValue(pointer, token, value) {
  if (pointer.value && typeof pointer.value === 'object') {
    if (token === '-' && Array.isArray(pointer.value)) {
      pointer.value.push(value);
    }
    else {
      pointer.value[token] = value;
    }
  }
  else {
    throw ono.syntax('Error assigning $ref pointer "%s". \nCannot set "%s" of a non-object.', pointer.url, token);
  }
  return value;
}
github APIDevTools / swagger-express-middleware / lib / middleware / parse-request / parse-parameter / index.js View on Github external
function parseError (error, parseInfo) {
  let { param, path } = parseInfo;

  let message = `The "${param.name}" ${param.in} parameter is invalid.`;

  if (path !== param.name) {
    message += ` Error at ${path}.`;
  }

  return ono.syntax(error, { status: 400 }, message);
}
github APIDevTools / json-schema-ref-parser / lib / index.js View on Github external
.then(function (result) {
      if (!result || typeof result !== 'object' || Buffer.isBuffer(result)) {
        throw ono.syntax('"%s" is not a valid JSON Schema', me.$refs._root$Ref.path || result);
      }
      else {
        me.schema = result;
        return maybe(args.callback, Promise.resolve(me.schema));
      }
    })
    .catch(function (e) {
github APIDevTools / json-schema-ref-parser / lib / parse.js View on Github external
function returnTheSchema() {
      if (!file.data || typeof file.data !== 'object' || Array.isArray(file.data)) {
        reject(ono.syntax('"%s" is not a valid JSON Schema', url || file.data));
      }
      else {
        resolve(schema);
      }
    }
  });

ono

Throw better errors.

MIT
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis