function checkValues()

in src/components/CompareResults/subtestsLoader.ts [8:104]


function checkValues({
  baseRev,
  baseRepo,
  newRev,
  newRepo,
  framework,
  baseParentSignature,
  newParentSignature,
}: {
  baseRev: string | null;
  baseRepo: Repository['name'] | null;
  newRev: string | null;
  newRepo: Repository['name'] | null;
  framework: string | number | null;
  baseParentSignature: string | null;
  newParentSignature: string | null;
}): {
  baseRev: string;
  baseRepo: Repository['name'];
  newRev: string;
  newRepo: Repository['name'];
  frameworkId: Framework['id'];
  frameworkName: Framework['name'];
  baseParentSignature: string;
  newParentSignature: string;
} {
  if (baseRev === null) {
    throw new Error('The parameter baseRev is missing.');
  }

  if (baseRepo === null) {
    throw new Error('The parameter baseRepo is missing.');
  }

  if (newRev === null) {
    throw new Error('The parameter newRev is missing.');
  }

  if (newRepo === null) {
    throw new Error('The parameter newRepo is missing.');
  }

  const validRepoValues = Object.values(repoMap);
  if (!validRepoValues.includes(baseRepo)) {
    throw new Error(
      `The parameter baseRepo "${baseRepo}" should be one of ${validRepoValues.join(
        ', ',
      )}.`,
    );
  }
  if (!validRepoValues.includes(newRepo)) {
    throw new Error(
      `The parameter newRepo "${newRepo}" should be one of ${validRepoValues.join(
        ', ',
      )}.`,
    );
  }

  if (baseParentSignature === null) {
    throw new Error('The parameter baseParentSignature is missing.');
  }

  if (newParentSignature === null) {
    throw new Error('The parameter newParentSignature is missing.');
  }

  if (framework === null) {
    framework = 1; // default to talos so that manually typing the URL is easier
  }

  const frameworkId = +framework as Framework['id'];
  if (Number.isNaN(frameworkId)) {
    throw new Error(
      `The parameter framework should be a number, but it is "${framework}".`,
    );
  }
  const frameworkName = frameworks.find(
    (entry) => entry.id === frameworkId,
  )?.name;

  if (!frameworkName) {
    throw new Error(
      `The parameter framework isn't a valid value: "${framework}".`,
    );
  }

  return {
    baseRev,
    baseRepo,
    newRev,
    newRepo,
    frameworkId,
    frameworkName,
    baseParentSignature,
    newParentSignature,
  };
}