export function parseYamlContent()

in eng/tools/sdk-suppressions/src/common.ts [11:42]


export function parseYamlContent(yamlContent: string, path: string): {
  result: string | object | undefined | null;
  message: string;
}{
  let content = undefined;
  // if yaml file is not a valid yaml, catch error and return undefined
  try {
    content = yamlParse(yamlContent);
  } catch (error) {
    console.error(`The file parsing failed in the ${path}. Details: ${error}`);
    return {
      result: content,
      message: `The file parsing failed in the ${path}. Details: ${error}`
    };;
  }
  
  // if yaml file is empty, run yaml.safeload success but get undefined
  // to identify whether it is empty return null to distinguish.
  if (!content) {
    console.info(`The file in the ${path} has been successfully parsed, but it is an empty file.`)
    return {
      result: null,
      message: `The file in the ${path} has been successfully parsed, but it is an empty file.`
    };;
  }
  
  return {
    result: content,
    message: 'The file has been successfully parsed.'
  };
  
}