Repository navigation
BUG: Do not write to the stream that failed to open #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hjmjohnson
wants to merge
3
commits into
stack/fix-fslio-64bit-arithmetic
Choose a base branch
from
stack/fix-cifti-null-stream
base: stack/fix-fslio-64bit-arithmetic
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Drives cifti_tool at an unopenable -output path. A plain add_test cannot | ||
| # express this: PASS_REGULAR_EXPRESSION ignores the exit status, so a crash | ||
| # that printed the diagnostic first would still pass. | ||
|
|
||
| if(NOT TOOL OR NOT INPUT OR NOT BADOUT OR NOT GOODOUT) | ||
| message(FATAL_ERROR "TOOL, INPUT, BADOUT and GOODOUT are all required") | ||
| endif() | ||
|
|
||
| function(run_tool expect_result out_var) | ||
| execute_process(COMMAND ${TOOL} ${ARGN} | ||
| RESULT_VARIABLE result | ||
| OUTPUT_VARIABLE out | ||
| ERROR_VARIABLE err) | ||
| set(${out_var} "${out}${err}" PARENT_SCOPE) | ||
| if(NOT result STREQUAL "${expect_result}") | ||
| message(FATAL_ERROR | ||
| "expected result ${expect_result}, got '${result}'\n${out}${err}") | ||
| endif() | ||
| endfunction() | ||
|
|
||
| run_tool(1 bad_disp -input ${INPUT} -disp_cext -output ${BADOUT}) | ||
| if(NOT bad_disp MATCHES "failed to open") | ||
| message(FATAL_ERROR "missing the open-failure diagnostic:\n${bad_disp}") | ||
| endif() | ||
|
|
||
| run_tool(1 bad_eval -input ${INPUT} -eval_cext -eval_type show_summary | ||
| -output ${BADOUT}) | ||
| if(NOT bad_eval MATCHES "failed to open") | ||
| message(FATAL_ERROR "missing the open-failure diagnostic:\n${bad_eval}") | ||
| endif() | ||
|
|
||
| # An openable -output must still be written, so that refusing every write | ||
| # would not pass. | ||
| file(REMOVE ${GOODOUT}) | ||
| run_tool(0 good_disp -input ${INPUT} -disp_cext -output ${GOODOUT}) | ||
| if(NOT EXISTS ${GOODOUT}) | ||
| message(FATAL_ERROR "nothing written to ${GOODOUT}") | ||
| endif() | ||
| file(READ ${GOODOUT} written) | ||
| if(NOT written MATCHES "MapName") | ||
| message(FATAL_ERROR "extension not displayed:\n${written}") | ||
| endif() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Google Carbon] Move the
if (!ext)check (lines 224–227) abovefp = open_write_stream(opts->fout)and write that diagnostic tostderrinstead offp— otherwise-disp_cext -output existing.xmlclobbersexisting.xmlwith"** no CIFTI extension in ..."on failure!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That branch is unreachable from cifti_tool: process() returns at 'failed to read CIFTI ext' before disp_cifti_extension when there is no CIFTI extension, so -output is never opened. I confirmed it with an image that has no extension, so I left the order as is.