How to use the @boost/internal.RuntimeError function in @boost/internal

To help you get started, we’ve selected a few @boost/internal 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 milesj / boost / packages / pipeline / src / createWorkUnit.ts View on Github external
export default function createWorkUnit<input>(
  titleOrWorkUnit: string | WorkUnit&lt;{}, Input, Output&gt;,
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  action?: Action,
  scope?: unknown,
): WorkUnit&lt;{}, Input, Output&gt; {
  if (titleOrWorkUnit instanceof WorkUnit) {
    return titleOrWorkUnit;
  }

  if (typeof titleOrWorkUnit === 'string' &amp;&amp; typeof action === 'function') {
    return new Task(titleOrWorkUnit, scope ? action.bind(scope) : action);
  }

  throw new RuntimeError('pipeline', 'PL_INVALID_WORK_UNIT');
}
github milesj / boost / packages / translate / src / createTranslator.ts View on Github external
debug: debugOpt = false,
    fallbackLocale = 'en',
    locale,
    lookupType,
    resourceFormat = 'yaml',
  }: TranslatorOptions = {},
): Translator {
  const namespaces = toArray(namespace);
  const resourcePaths = toArray(resourcePath).map(Path.create);

  if (namespaces.length === 0) {
    throw new RuntimeError('translate', 'TL_REQ_NAMESPACE');
  } else if (resourcePaths.length === 0) {
    throw new RuntimeError('translate', 'TL_REQ_RES_PATHS');
  } else if (!autoDetect && !locale) {
    throw new RuntimeError('translate', 'TL_REQ_MANUAL_LOCALE');
  }

  debug('New translator created: %s namespace(s)', namespaces.join(', '));

  const translator = i18next.createInstance().use(new FileBackend());

  if (autoDetect) {
    translator.use(new LocaleDetector());
  }

  translator.init(
    {
      backend: {
        format: resourceFormat,
        paths: resourcePaths,
      },
github milesj / boost / packages / translate / src / createTranslator.ts View on Github external
{
    autoDetect = true,
    debug: debugOpt = false,
    fallbackLocale = 'en',
    locale,
    lookupType,
    resourceFormat = 'yaml',
  }: TranslatorOptions = {},
): Translator {
  const namespaces = toArray(namespace);
  const resourcePaths = toArray(resourcePath).map(Path.create);

  if (namespaces.length === 0) {
    throw new RuntimeError('translate', 'TL_REQ_NAMESPACE');
  } else if (resourcePaths.length === 0) {
    throw new RuntimeError('translate', 'TL_REQ_RES_PATHS');
  } else if (!autoDetect && !locale) {
    throw new RuntimeError('translate', 'TL_REQ_MANUAL_LOCALE');
  }

  debug('New translator created: %s namespace(s)', namespaces.join(', '));

  const translator = i18next.createInstance().use(new FileBackend());

  if (autoDetect) {
    translator.use(new LocaleDetector());
  }

  translator.init(
    {
      backend: {
        format: resourceFormat,
github milesj / boost / packages / args / src / Checker.ts View on Github external
logFailureError(module: string, args?: unknown[]) {
    this.logFailure(new RuntimeError('args', module, args).message);
  }
github milesj / boost / packages / plugin / src / Manager.ts View on Github external
get(name: ModuleName): Plugin {
    const plugin = this.plugins.find(container => this.isMatchingName(container, name));

    if (plugin) {
      return plugin.plugin;
    }

    throw new RuntimeError('plugin', 'PG_MISSING_PLUGIN', [this.singularName, name]);
  }
github milesj / boost / packages / translate / src / FileBackend.ts View on Github external
this.options.paths.forEach(path => {
      if (path.exists() && !path.isDirectory()) {
        throw new RuntimeError('translate', 'TL_INVALID_RES_PATH', [path.path()]);
      }
    });
  }
github milesj / boost / packages / plugin / src / Registry.ts View on Github external
getRegisteredType(typeName: K): PluginType {
    const type = this.types[typeName];

    if (!type) {
      throw new RuntimeError('plugin', 'PG_MISSING_TYPE', [typeName]);
    }

    return type!;
  }
github milesj / boost / packages / cli / src / decorators / Name.ts View on Github external
return (target: Object) => {
    if (!name.match(COMMAND_FORMAT)) {
      throw new RuntimeError('args', 'AG_COMMAND_INVALID_FORMAT', [name]);
    }

    Reflect.defineMetadata(META_NAME, name, target);
  };
}
github milesj / boost / packages / common / src / helpers / parseFile.ts View on Github external
switch (path.ext()) {
    case '.js':
    case '.jsx':
      return requireModule(path);

    case '.json':
    case '.json5':
      return JSON5.parse(fs.readFileSync(path.path(), 'utf8'));

    case '.yml':
    case '.yaml':
      return YAML.safeLoad(fs.readFileSync(path.path(), 'utf8'));

    default:
      throw new RuntimeError('common', 'CM_PARSE_INVALID_EXT', [path.name()]);
  }
}