phrase / phrase-cli

CLI for the Phrase API
https://developers.phrase.com
MIT License
42 stars 5 forks source link

Push error handling #135

Closed jimmymcpeter closed 9 months ago

jimmymcpeter commented 11 months ago

Hi, what would you recommend I do regarding an error during a push of multiple source files? The exit code is always 0 and I don't see any option to exit on error.

PS C:\source> phrase version  
2.15.0

PS C:\source> phrase push --wait
Uploading source\file1.csv... 
Upload Id: xxxxx, filename: file1.csv succeeded. Waiting for your file to be processed...  
There was an error processing source\file1.csv. Your changes were not saved online.
Uploading source\file2.csv...
Upload Id: yyyyy, filename: file2.csv succeeded. Waiting for your file to be processed...  
Successfully uploaded and processed source\file2.csv.

PS C:\source>$LASTEXITCODE
0
PS C:\source> $?
True

Edit: Actually, the error code is 0 even with 1 source file configured.

jablan commented 11 months ago

@jimmymcpeter thanks, well spotted. We'll open an internal issue to address this. Do you think the batch upload should stop on first error? That could probably be set through an optional parameter.

jimmymcpeter commented 11 months ago

Do you think the batch upload should stop on first error? That could probably be set through an optional parameter.

I'm using the CLI through a GitHub Action. I really need a non-zero exit code returned otherwise the action returns it was a success.

image

jablan commented 11 months ago

That much is clear, we'll add non-zero exit code. The question is only, would it be preferred for the command to exit as soon as the first uploaded file fails, or is it OK like this, that we proceed with all the files, and only then return non-zero code?

jimmymcpeter commented 11 months ago

Sorry I dodged your initial question. It's OK like it this. Maybe you add the abort on error parameter as an enhancement idea for the future? 😃

jimmymcpeter commented 11 months ago

I added a workaround into my GH action using tee and grep. Hopefully this is helpful for a few others --

logfile="phrase.log"

phrase push --wait --config ${{ inputs.config_file }} | tee -a $logfile

if grep -q "There was an error" $logfile; then
    echo "Phrase Strings Push encountered an error"
    exit 1
fi