Skip to content

Commit 8a27bbb

Browse files
authored
Merge pull request #442 from infosiftr/js-yaml-errors
Try harder to surface js-yaml parsing errors directly
2 parents 85bc1c3 + fb98204 commit 8a27bbb

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

3.6/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ _parse_config() {
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155155
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156+
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157+
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
158+
echo >&2 'error: unexpected "js-yaml.js" output while parsing config:'
159+
cat >&2 "$jsonConfigFile"
160+
exit 1
161+
fi
156162
jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile"
157163
return 0
158164
fi

4.0/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ _parse_config() {
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155155
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156+
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157+
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
158+
echo >&2 'error: unexpected "js-yaml.js" output while parsing config:'
159+
cat >&2 "$jsonConfigFile"
160+
exit 1
161+
fi
156162
jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile"
157163
return 0
158164
fi

4.2/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ _parse_config() {
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155155
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156+
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157+
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
158+
echo >&2 'error: unexpected "js-yaml.js" output while parsing config:'
159+
cat >&2 "$jsonConfigFile"
160+
exit 1
161+
fi
156162
jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile"
157163
return 0
158164
fi

4.4/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ _parse_config() {
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155155
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156+
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157+
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
158+
echo >&2 'error: unexpected "js-yaml.js" output while parsing config:'
159+
cat >&2 "$jsonConfigFile"
160+
exit 1
161+
fi
156162
jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile"
157163
return 0
158164
fi

docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ _parse_config() {
153153
# if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys)
154154
# see https://docs.mongodb.com/manual/reference/configuration-options/
155155
mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile"
156+
if [ "$(head -c1 "$jsonConfigFile")" != '{' ] || [ "$(tail -c2 "$jsonConfigFile")" != '}' ]; then
157+
# if the file doesn't start with "{" and end with "}", it's *probably* an error ("uncaught exception: YAMLException: foo" for example), so we should print it out
158+
echo >&2 'error: unexpected "js-yaml.js" output while parsing config:'
159+
cat >&2 "$jsonConfigFile"
160+
exit 1
161+
fi
156162
jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile"
157163
return 0
158164
fi

0 commit comments

Comments
 (0)