How to use the @stryker-mutator/util.StrykerError function in @stryker-mutator/util

To help you get started, we’ve selected a few @stryker-mutator/util 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 stryker-mutator / stryker / packages / stryker / src / input / InputFileResolver.ts View on Github external
private async resolveFilesUsingGit(): Promise {
    try {
      const { stdout } = await childProcessAsPromised.exec(
        'git ls-files --others --exclude-standard --cached --exclude .stryker-tmp',
        { maxBuffer: 10 * 1000 * 1024 }
      );
      const fileNames = stdout.toString()
        .split('\n')
        .map(line => line.trim())
        .filter(line => line) // remove empty lines
        .map(relativeFileName => path.resolve(relativeFileName));
      return fileNames;
    } catch (error) {
      throw new StrykerError(normalizeWhiteSpaces(
        `Cannot determine input files. Either specify a \`files\`
        array in your stryker configuration, or make sure "${process.cwd()}"
        is located inside a git repository`),
        error
      );
    }
  }
github stryker-mutator / stryker / packages / core / src / input / InputFileResolver.ts View on Github external
private async resolveFilesUsingGit(): Promise {
    try {
      const { stdout } = await childProcessAsPromised.exec(`git ls-files --others --exclude-standard --cached --exclude /${this.tempDirName}/*`, {
        maxBuffer: 10 * 1000 * 1024
      });
      const fileNames = stdout
        .toString()
        .split('\n')
        .map(line => line.trim())
        .filter(line => line) // remove empty lines
        .map(relativeFileName => path.resolve(relativeFileName));
      return fileNames;
    } catch (error) {
      throw new StrykerError(
        normalizeWhitespaces(
          `Cannot determine input files. Either specify a \`files\`
        array in your stryker configuration, or make sure "${process.cwd()}"
        is located inside a git repository`
        ),
        error
      );
    }
  }
github stryker-mutator / stryker / packages / stryker / src / transpiler / CoverageInstrumenterTranspiler.ts View on Github external
private instrumentFile(sourceFile: File): File {
    try {
      const content = this.instrumenter.instrumentSync(sourceFile.textContent, sourceFile.name);
      const fileCoverage = this.patchRanges(this.instrumenter.lastFileCoverage());
      this.fileCoverageMaps[sourceFile.name] = this.retrieveCoverageMaps(fileCoverage);
      return new File(sourceFile.name, Buffer.from(content));
    } catch (error) {
      throw new StrykerError(`Could not instrument "${sourceFile.name}" for code coverage`, error);
    }
  }
github stryker-mutator / stryker / packages / core / src / reporters / dashboard-reporter / DashboardReporterClient.ts View on Github external
this.log.info('PUT report to %s (~%s bytes)', url, serializedBody.length);
    const apiKey = getEnvironmentVariable(STRYKER_DASHBOARD_API_KEY);
    if (apiKey) {
      this.log.debug('Using configured API key from environment "%s"', STRYKER_DASHBOARD_API_KEY);
    }
    this.log.trace('PUT report %s', serializedBody);
    const result = await this.httpClient.put(url, serializedBody, {
      ['X-Api-Key']: apiKey,
      ['Content-Type']: 'application/json'
    });
    const responseBody = await result.readBody();
    if (isOK(result.message.statusCode || 0)) {
      const response: ReportResponseBody = JSON.parse(responseBody);
      return response.href;
    } else if (result.message.statusCode === 401) {
      throw new StrykerError(
        `Error HTTP PUT ${url}. Unauthorized. Did you provide the correct api key in the "${STRYKER_DASHBOARD_API_KEY}" environment variable?`
      );
    } else {
      throw new StrykerError(`Error HTTP PUT ${url}. Response status code: ${result.message.statusCode}. Response body: ${responseBody}`);
    }
  }
github stryker-mutator / stryker / packages / core / src / transpiler / TranspilerFacade.ts View on Github external
const output = await current.transpiler.transpile(input).catch(error => {
        throw new StrykerError(`An error occurred in transpiler "${current.name}"`, error);
      });
      return this.performTranspileChain(output, remainingChain);
github stryker-mutator / stryker / packages / core / src / config / ConfigReader.ts View on Github external
this.log.info('Use `stryker init` command to generate your config file.');
      }
    }

    if (this.cliOptions.configFile) {
      this.log.debug(`Loading config ${this.cliOptions.configFile}`);
      const configFileName = path.resolve(this.cliOptions.configFile);
      try {
        configModule = require(configFileName);
      } catch (e) {
        if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(this.cliOptions.configFile) !== -1) {
          throw new StrykerError(`File ${configFileName} does not exist!`, e);
        } else {
          this.log.info('Stryker can help you setup a `stryker.conf` file for your project.');
          this.log.info("Please execute `stryker init` in your project's root directory.");
          throw new StrykerError('Invalid config file', e);
        }
      }
      if (typeof configModule !== 'function' && typeof configModule !== 'object') {
        this.log.fatal('Config file must be an object or export a function!\n' + CONFIG_SYNTAX_HELP);
        throw new StrykerError('Config file must export a function or be a JSON!');
      }
      if (typeof configModule === 'object') {
        return (config: any) => {
          config.set(configModule);
        };
      }
    }

    return configModule;
  }
}
github stryker-mutator / stryker / packages / stryker / src / config / ConfigValidator.ts View on Github external
private crashIfNeeded() {
    if (!this.isValid) {
      throw new StrykerError('Stryker could not recover from this configuration error, see fatal log message(s) above.');
    }
  }
github stryker-mutator / stryker / packages / core / src / config / ConfigReader.ts View on Github external
this.log.debug(`Loading config ${this.cliOptions.configFile}`);
      const configFileName = path.resolve(this.cliOptions.configFile);
      try {
        configModule = require(configFileName);
      } catch (e) {
        if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(this.cliOptions.configFile) !== -1) {
          throw new StrykerError(`File ${configFileName} does not exist!`, e);
        } else {
          this.log.info('Stryker can help you setup a `stryker.conf` file for your project.');
          this.log.info("Please execute `stryker init` in your project's root directory.");
          throw new StrykerError('Invalid config file', e);
        }
      }
      if (typeof configModule !== 'function' && typeof configModule !== 'object') {
        this.log.fatal('Config file must be an object or export a function!\n' + CONFIG_SYNTAX_HELP);
        throw new StrykerError('Config file must export a function or be a JSON!');
      }
      if (typeof configModule === 'object') {
        return (config: any) => {
          config.set(configModule);
        };
      }
    }

    return configModule;
  }
}