Skip to content

Commit

Permalink
improve yaml handling (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloep authored Feb 10, 2022
1 parent 08a0469 commit 9b2fe31
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,31 @@ export async function readPackageYml(addonDir: string): Promise<PackageYml> {
const packageYmlPath = path.join(addonDir, '/', 'package.yml');
Core.info(`Parsing yaml from ${packageYmlPath}`);
const packageYmlString = fs.readFileSync(packageYmlPath, {encoding: 'utf8'});
return YAML.parse(packageYmlString);

try {
return YAML.parse(packageYmlString, {
prettyErrors: true,
});
} catch (originalError) {
Core.error(`Failed to parse yaml from ${packageYmlPath}. Try to fix it automatically.`);

// try to escape "perm" value
const fixedPackageYmlString = packageYmlString.replace(/(perm:[.\s\n\r\t]*)([a-z0-9_]+\[[a-z0-9_]+\])/ig, `$1'$2'`);

// second try with escaped "perm" value
try {
const parsedYaml = YAML.parse(fixedPackageYmlString, {
prettyErrors: true,
});
Core.info(`Successfully parsed yaml with fixed values.`);

return parsedYaml;
} catch (_) {
// failed to parse yaml with fixed values
Core.error(`Automatically fixed yaml failed. Please fix it manually.`);
throw originalError;
}
}
}

export function md5_file(file: string): Promise<string> {
Expand Down

0 comments on commit 9b2fe31

Please sign in to comment.