Commit 385bc2ca authored by isherman's avatar isherman Committed by Commit bot

[Metrics] Fix presubmit scripts to set an error exit code on failure.

Due to a bug in a recent refactoring, the script would log an error to the
console, but would still set the success exit code, 0.

BUG=468523
TEST=Try to submit a CL with invalid formatting, the presubmit script should block submission.
R=asvitkine@chromium.org

Review URL: https://codereview.chromium.org/1019123003

Cr-Commit-Position: refs/heads/master@{#321436}
parent 33048354
......@@ -47,27 +47,27 @@ def DoPresubmitMain(argv, original_filename, backup_filename, script_name,
if '\r' in original_xml:
logging.error('DOS-style line endings (CR characters) detected - these are '
'not allowed. Please run dos2unix %s', original_filename)
return 1
sys.exit(1)
try:
pretty = prettyFn(original_xml)
except Error:
logging.error('Aborting parsing due to fatal errors.')
return 1
sys.exit(1)
if original_xml == pretty:
logging.info('%s is correctly pretty-printed.', original_filename)
return 0
sys.exit(0)
if presubmit:
logging.error('%s is not formatted correctly; run %s to fix.',
original_filename, script_name)
return 1
sys.exit(1)
# Prompt user to consent on the change.
if not diff_util.PromptUserToAcceptDiff(
original_xml, pretty, 'Is the new version acceptable?'):
logging.error('Diff not accepted. Aborting.')
return 1
sys.exit(1)
logging.info('Creating backup file: %s', backup_filename)
shutil.move(xml_path, os.path.join(xml_dir, backup_filename))
......@@ -76,4 +76,4 @@ def DoPresubmitMain(argv, original_filename, backup_filename, script_name,
f.write(pretty)
logging.info('Updated %s. Don\'t forget to add it to your changelist',
xml_path)
return 0
sys.exit(0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment