Skip to content

Commit 888fee5

Browse files
committed
Even better YAML errors
1 parent dd87b4e commit 888fee5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/appdistribution/yaml_helper.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as jsYaml from "js-yaml";
2-
import { FirebaseError } from "../error";
2+
import { getErrMsg, FirebaseError } from "../error";
33
import { TestCase } from "./types";
44

55
declare interface YamlStep {
@@ -63,9 +63,7 @@ function checkAllowedKeys(allowedKeys: Set<string>, o: object) {
6363
}
6464

6565
function fromYamlTestCases(appName: string, yamlTestCases: YamlTestCase[]): TestCase[] {
66-
if (!Array.isArray(yamlTestCases)) {
67-
throw new FirebaseError("YAML file must contain a list of test cases.");
68-
}
66+
6967
return yamlTestCases.map((yamlTestCase) => {
7068
checkAllowedKeys(ALLOWED_YAML_TEST_CASE_KEYS, yamlTestCase);
7169
return {
@@ -93,5 +91,14 @@ function fromYamlTestCases(appName: string, yamlTestCases: YamlTestCase[]): Test
9391
}
9492

9593
export function fromYaml(appName: string, yaml: string): TestCase[] {
96-
return fromYamlTestCases(appName, jsYaml.safeLoad(yaml) as YamlTestCase[]);
94+
let parsedYaml: unknown
95+
try {
96+
parsedYaml = jsYaml.safeLoad(yaml)
97+
} catch (err: unknown) {
98+
throw new FirebaseError(`Failed to parse YAML: ${getErrMsg(err)}`)
99+
}
100+
if (!Array.isArray(parsedYaml)) {
101+
throw new FirebaseError("YAML file must contain a list of test cases.");
102+
}
103+
return fromYamlTestCases(appName, parsedYaml as YamlTestCase[]);
97104
}

0 commit comments

Comments
 (0)