function tryYAMLParse(contents, defaultValue) { try { return yaml.safeLoad(contents) || defaultValue; } catch (err) { if (err instanceof yaml.YAMLException) { return defaultValue; } throw err; } }
static instanceWithContext (context) { return Configuration.fetchConfigFile(context).then(config => { return new Configuration(config) }).catch(error => { let config = new Configuration() if (error instanceof ConfigFileNotFoundException) { config.errors.set(ERROR_CODES.NO_YML, `No Config File found`) } else if (error instanceof yaml.YAMLException) { config.errors.set(ERROR_CODES.BAD_YML, `Invalid YML format > ${error.message}`) } else { const errorMsg = `Github API Error occurred while fetching the config file at ${Configuration.FILE_NAME} \n Error from api: ${error}` config.errors.set(ERROR_CODES.GITHUB_API_ERROR, errorMsg) } return config }) }
const context = createMockGhConfig() context.probotContext.config = jest.fn().mockImplementation(() => { throw new yaml.YAMLException('Bad YML') })