How to use yerror - 10 common examples

To help you get started, we’ve selected a few yerror 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 nfroidure / jsarch / src / jsarch.js View on Github external
log('debug', 'Reading file at', filePath);

  try {
    content = await fs.readFileAsync(filePath, 'utf-8');

    log('debug', 'File sucessfully read', filePath);

    if (SHEBANG_REGEXP.test(content)) {
      log('debug', 'Found a shebang, commenting it', filePath);
      content = '// Shebang commented by jsarch: ' + content;
    }
  } catch (err) {
    log('error', 'File read failure:', filePath);
    log('stack', 'Stack:', err.stack);
    throw YError.wrap(err, 'E_FILE_FAILURE', filePath);
  }

  try {
    const ast = parser(content);
    const architectureNotes = [];

    visit(ast, {
      visitComment: function(path) {
        const comment = path.value.value;
        const matches = ARCHITECTURE_NOTE_REGEXP.exec(comment);

        if (matches) {
          architectureNotes.push({
            num: matches[1],
            title: matches[2].trim(),
            content: comment.substr(matches[0].length).trim(),
github nfroidure / knifecycle / src / index.js View on Github external
siloContext,
    serviceName,
    { injectorContext, autoloading },
  ) {
    let initializer = this._initializers.get(serviceName);

    if (initializer) {
      return initializer;
    }

    // The auto loader must only have static dependencies
    // and we have to do this check here to avoid caching
    // non-autoloading request and then be blocked by an
    // autoloader dep that waits for that cached load
    if (autoloading) {
      throw new YError(E_AUTOLOADER_DYNAMIC_DEPENDENCY, serviceName);
    }

    debug('No service provider:', serviceName);

    let initializerPromise = this._initializerResolvers.get(serviceName);

    if (initializerPromise) {
      return await initializerPromise;
    }

    initializerPromise = (async () => {
      if (!this._initializers.get(AUTOLOAD)) {
        throw new YError(E_UNMATCHED_DEPENDENCY, serviceName);
      }
      debug(`Loading the $autoload service to lookup for: ${serviceName}.`);
      try {
github nfroidure / metapak / src / resolveModule.js View on Github external
return function resolveModule(metapakModuleName, packageConf) {
    try {
      // Cover the case a metapak plugin runs itself
      if (metapakModuleName === packageConf.name) {
        return path.dirname(require.resolve(`${PROJECT_DIR}/package`));
      }
      return path.dirname(require.resolve(`${metapakModuleName}/package`));
    } catch (err) {
      throw YError.wrap(err, 'E_MODULE_NOT_FOUND', metapakModuleName);
    }
  };
}
github nfroidure / knifecycle / src / util.js View on Github external
) {
  const matches = source.match(
    /^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\s*\{\s*([^{}}]+)\s*\}/,
  );

  if (!matches) {
    if (!source.match(/^\s*async/)) {
      throw new YError('E_NON_ASYNC_INITIALIZER', source);
    }
    if (
      allowEmpty &&
      source.match(/^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\s*\)/)
    ) {
      return [];
    }
    throw new YError('E_AUTO_INJECTION_FAILURE', source);
  }

  return matches[1]
    .trim()
    .replace(/,$/, '')
    .split(/\s*,\s*/)
    .map(
      injection =>
        (injection.includes('=') ? '?' : '') +
        injection
          .split(/\s*=\s*/)
          .shift()
          .split(/\s*:\s*/)
          .shift(),
    )
    .filter(injection => !/[)(\][]/.test(injection));
github nfroidure / knifecycle / src / util.js View on Github external
export function parseInjections(
  source,
  { allowEmpty = false } = { allowEmpty: false },
) {
  const matches = source.match(
    /^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\s*\{\s*([^{}}]+)\s*\}/,
  );

  if (!matches) {
    if (!source.match(/^\s*async/)) {
      throw new YError('E_NON_ASYNC_INITIALIZER', source);
    }
    if (
      allowEmpty &&
      source.match(/^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\s*\)/)
    ) {
      return [];
    }
    throw new YError('E_AUTO_INJECTION_FAILURE', source);
  }

  return matches[1]
    .trim()
    .replace(/,$/, '')
    .split(/\s*,\s*/)
    .map(
      injection =>
github nfroidure / knifecycle / src / index.mocha.js View on Github external
it('should disallow new runs', async () => {
      $.register(constant('ENV', ENV));
      $.register(constant('time', time));
      $.register(provider(hashProvider, 'hash', ['ENV']));
      $.register(provider(hashProvider, 'hash1', ['ENV']));

      const dependencies = await $.run(['$instance']);

      assert.equal(typeof dependencies.$instance.destroy, 'function');

      await dependencies.$instance.destroy();

      try {
        await $.run(['ENV', 'hash', 'hash1']);
        throw new YError('E_UNEXPECTED_SUCCES');
      } catch (err) {
        assert.equal(err.code, 'E_INSTANCE_DESTROYED');
      }
    });
  });
github nfroidure / metapak / src / metapak.js View on Github external
if (packageConfModified) {
        log(
          'info',
          '🚧 - The project package.json changed, you may want' +
            ' to `npm install` again to install new dependencies.'
        );
      }
      if (assetsModified) {
        log(
          'info',
          '🚧 - Some assets were added to the project, you may want to stage them.'
        );
      }
      exit(0);
    } catch (err) {
      const castedErr = YError.cast(err);

      log(
        'error',
        '💀 - Could not run metapak script correctly:',
        castedErr.code,
        castedErr.params
      );
      log('info', '💊 - Debug by running again with "DEBUG=metapak" env.');
      log('stack', castedErr.stack);
      exit(1);
    }
  };
}
github nfroidure / knifecycle / src / build.mocha.js View on Github external
return async function $autoload(name) {
        return mockedDepsHash[name]
          ? Promise.resolve({
              path: `./services/${name}`,
              initializer: mockedDepsHash[name],
            })
          : Promise.reject(new YError('E_UNMATCHED_DEPENDENCY', name));
      };
    },
github nfroidure / knifecycle / src / index.js View on Github external
initializer[SPECIAL_PROPS.INJECT].reduce(
          (finalHash, dependencyDeclaration) => {
            const { serviceName, mappedName } = parseDependencyDeclaration(
              dependencyDeclaration,
            );

            finalHash[serviceName] = servicesHash[mappedName];
            return finalHash;
          },
          {},
        ),
      );

      if (!serviceDescriptor) {
        debug('Provider did not return a descriptor:', serviceName);
        return Promise.reject(new YError(E_BAD_SERVICE_PROVIDER, serviceName));
      }
      debug('Successfully initialized a service descriptor:', serviceName);
      if (serviceDescriptor.fatalErrorPromise) {
        debug('Registering service descriptor error promise:', serviceName);
        siloContext.errorsPromises.push(serviceDescriptor.fatalErrorPromise);
      }
      siloContext.servicesDescriptors.set(serviceName, serviceDescriptor);
    } catch (err) {
      debug('Error initializing a service descriptor:', serviceName, err.stack);
      if (E_UNMATCHED_DEPENDENCY === err.code) {
        throw YError.wrap(
          ...[err, E_UNMATCHED_DEPENDENCY, serviceName].concat(err.params),
        );
      }
      throw err;
    }
github nfroidure / knifecycle / src / index.js View on Github external
register(initializer) {
    if (this.shutdownPromise) {
      throw new YError(E_INSTANCE_DESTROYED);
    }
    if (typeof initializer !== 'function') {
      throw new YError(E_BAD_INITIALIZER, initializer);
    }
    initializer[SPECIAL_PROPS.INJECT] = initializer[SPECIAL_PROPS.INJECT] || [];
    initializer[SPECIAL_PROPS.OPTIONS] =
      initializer[SPECIAL_PROPS.OPTIONS] || {};
    initializer[SPECIAL_PROPS.TYPE] =
      initializer[SPECIAL_PROPS.TYPE] || ALLOWED_INITIALIZER_TYPES[0];
    if (!initializer[SPECIAL_PROPS.NAME]) {
      throw new YError(E_ANONYMOUS_ANALYZER, initializer[SPECIAL_PROPS.NAME]);
    }
    if (
      initializer[SPECIAL_PROPS.NAME] === AUTOLOAD &&
      !initializer[SPECIAL_PROPS.OPTIONS].singleton
    ) {
      throw new YError(E_BAD_AUTOLOADER, initializer[SPECIAL_PROPS.OPTIONS]);
    }
    if (!ALLOWED_INITIALIZER_TYPES.includes(initializer[SPECIAL_PROPS.TYPE])) {

yerror

It helps to know why you got an error.

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis

Popular yerror functions