Skip to content
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

return error levels/codes to shell on error #479

Closed
pageauc opened this issue Nov 11, 2015 · 13 comments
Closed

return error levels/codes to shell on error #479

pageauc opened this issue Nov 11, 2015 · 13 comments
Assignees
Milestone

Comments

@pageauc
Copy link

pageauc commented Nov 11, 2015

I am using the program on a raspberry pi bash script using Raspbian Jessie. I want to detect an errorlevel if there is an error like not being able to connect or a failed push/pull etc. Normally a program will return an error level of 0 if successful and non zero if a problem is encountered.
Can you confirm if there are error levels returned in this program.
Thanks Claude ...

@odeke-em
Copy link
Owner

Hello again @pageauc,
Good question, so in Go an os.Exit(error) produces a non zero error code while os.Exit(nil) produces a zero error code and that's what drive does depending on if the operation flow encounters an error or not.
So far, contributors have raised issues where errors haven't been properly raised and those issues have been addressed. Is there a case that failed to work for you? If you notice anything peculiar, please feel free to raise an issue and I'll work on it.

@ikwyl6
Copy link

ikwyl6 commented Nov 11, 2015

I think what the user may be looking for (correct me if I'm wrong) is a list of different error codes for different exit status situations. This helps tremendously when someone wants to use your drive script in their script and notify the user of why an error was thrown. You have already included text descriptions with your script but the user may want to do it a different way. Otherwise if you don't assign exit codes to different errors, they only know that drive threw an "exit 1" (as an example) but there is no explanation why (if the user wants to suppress your output).

Usually in C programming there can be an "errors.h" file or something similar that lists all error types. For example:

  • exit 1: user enters wrong credentials
  • exit 2: drive was cancelled by user (CTRL-c)
  • exit 3: drive was disconnected from server.

And so on. This list could be big. This makes the error situations very manageable when someone wants to cleanly notify the user of why the script ended without a 0 exit code.

@pageauc
Copy link
Author

pageauc commented Nov 11, 2015

Yes that is exactly what I am trying to do with my bash script. I am automating recording and uploading video files in a round robin sequence. If a process fails (record, upload, etc) then I want to take appropriate action like retry upload, record etc. I also have to check to make sure that if multiple instances of the script are run, that the current state is not crashed eg tries to duplicate something that is already in progress. I need to report meaningful status, warning or error message(s) to the users(s), It is nice to have self correcting code but in some cases users might need to resolve a problem. A list of exit codes would be great since one process can communicate to another like a record failing so don't upload it. If problem persists then issue appropriate message.

This works
if [ $? -ne 0 ]; then
The program will return error messages like "blah blah .. lookup accounts.google.com: no such host"
but I would like to fine tune a little better depending on the severity within the script.

Thanks Claude ...

@odeke-em
Copy link
Owner

Thank you @ikwyl6 for the clarification, that makes sense. @pageauc so no there isn't a list of exit codes, currently the only exit code is either 1 or 0
img_20151111_134737

@ikwyl6
Copy link

ikwyl6 commented Nov 12, 2015

Hi @odeke-em so do you think you can implement these error codes?

@odeke-em
Copy link
Owner

I don't know about now as I don't have much free time. In the next two months or so, sure, given the number of unfixed bugs plus my school commitments. Otherwise if anyone would like they can submit a PR and I'll definitely review it.

@odeke-em
Copy link
Owner

Hello @ikwyl6 and @pageauc did you have an idea of the different error codes or would you like me to add them in in running number form ie 1 counting upwards, and then you'll look them up?

@pageauc
Copy link
Author

pageauc commented Nov 27, 2015

Ok. These are my suggestions but not sure if you have appropriate points
in the program to trap these types of errors. Some of these I can check
with another program prior to launching a sync. Eg No Connection. It would
be nicer to have this done within a returned errorlevel.
Claude ...

0 - Sync Successful
1 - Sync Incomplete - Lost Connection due to Local Network or Internet
Problem
2 - Sync Incomplete - File Permission, Space, Etc Problem
3 - Sync Failed -.Authentication with Server Failed
4 - Sync Failed - Server or API Service Not Found Problem
5 - No Connection - Local Network or Internet Problem.

On Fri, Nov 27, 2015 at 10:06 AM, Emmanuel T Odeke <notifications@github.com

wrote:

Hello @ikwyl6 https://github.com/ikwyl6 and @pageauc
https://github.com/pageauc did you have an idea of the different error
codes or would you like me to add them in in running number form ie 1
counting upwards, and then you'll look them up?


Reply to this email directly or view it on GitHub
#479 (comment).

See my YouTube Channel at http://www.youtube.com/user/pageaucp

@odeke-em odeke-em changed the title Does program return error levels for bash script return error levels/codes to shell on error Dec 2, 2015
@HontoNoRoger
Copy link

+1 for that

@emmtte
Copy link

emmtte commented Jan 26, 2016

I need it too after spent files with a pull/push script with non possiblity to read status code 504 & 505

odeke-em added a commit that referenced this issue Mar 25, 2016
Fixes #479.

Now most errors returned from drive have a status/return
code that will be passed to the external environment on failure.

- Before
```shell
$ drive pull nonExistant
$ echo $?
1
```

- After
```shell
$ drive pull nonExistant
$ echo $?
8
```
odeke-em added a commit that referenced this issue Mar 25, 2016
Fixes #479.

Now most errors returned from drive have a status/return
code that will be passed to the external environment on failure.

- Before
```shell
$ drive pull nonExistant
Resolving...
 –
'/ysms' aka '/Users/emmanuelodeke/emm.odeke/nonExistant' doesn't
exist locally nor remotely
$ echo $?
1
$ mkfifo pxm
$ drive push pxm
Resolving...
 –
/pxm (/Users/emmanuelodeke/emm.odeke/pxm) is a named pipe, yet
not reading from it
$ echo $?
1
```

- After
```shell
$ drive pull nonExistant
$ echo $?
8
$ mkfifo pxm
$ drive push pxm
Resolving...
 –
/pxm (/Users/emmanuelodeke/emm.odeke/pxm) is a named pipe, yet
not reading from it
$ echo $?
22
```
@odeke-em
Copy link
Owner

Hey folks. My apologies for the long wait, I have been very busy for the last few months. However, this evening I got some time and whipped up a PR #608. It has a couple of status/return codes and you can always see the reference in src/errors.go. I'll merge it in and we'll keep updating it as we go.
Thanks y'all.

odeke-em added a commit that referenced this issue Mar 25, 2016
Fixes #479.

Now most errors returned from drive have a status/return
code that will be passed to the external environment on failure.

- Before
```shell
$ drive pull nonExistant
Resolving...
 –
'/ysms' aka '/Users/emmanuelodeke/emm.odeke/nonExistant' doesn't
exist locally nor remotely
$ echo $?
1
$ mkfifo pxm
$ drive push pxm
Resolving...
 –
/pxm (/Users/emmanuelodeke/emm.odeke/pxm) is a named pipe, yet
not reading from it
$ echo $?
1
```

- After
```shell
$ drive pull nonExistant
$ echo $?
8
$ mkfifo pxm
$ drive push pxm
Resolving...
 –
/pxm (/Users/emmanuelodeke/emm.odeke/pxm) is a named pipe, yet
not reading from it
$ echo $?
22
```
@odeke-em odeke-em added this to the v0.3.6 milestone Mar 25, 2016
@odeke-em odeke-em self-assigned this Mar 25, 2016
@odeke-em
Copy link
Owner

Auto closed by PR #608, please re-open if persists.

@emmtte
Copy link

emmtte commented Mar 25, 2016

Thanks a lot I try it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants