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

Different error codes for different OS configurations #52

Closed
EliuX opened this issue May 15, 2018 · 3 comments
Closed

Different error codes for different OS configurations #52

EliuX opened this issue May 15, 2018 · 3 comments

Comments

@EliuX
Copy link

EliuX commented May 15, 2018

I am using MEGACmd from a client program and while developing and testing it in Windows I was able to get error codes that made sense to each particular situation. Afterwards when I ran such tests in Ubuntu/Linux, in Travis and later in a personal PC I always got error codes not present in megacmd.h.

Notes

  • The error codes I am getting has positive values, e.g. 199.
  • In windows the commands where run using the MegaClient and the mega-<command> batch files.
  • In Linux the commands where run using mega-<command> in a bash shell.

Configuration in Windows 10

MEGA CMD version: 0.9.9: code 90900
MEGA SDK version: 3.3.5
MEGA SDK Credits: https://github.com/meganz/sdk/blob/master/CREDITS.md
MEGA SDK License: https://github.com/meganz/sdk/blob/master/LICENSE
MEGAcmd License: https://github.com/meganz/megacmd/blob/master/LICENSE
Features enabled:

  • CryptoPP
  • SQLite
  • FreeImage
  • sync subsystem

Configuration in Ubuntu 15.10

MEGA CMD version: 0.9.9: code 90900
MEGA SDK version: 3.3.5
MEGA SDK Credits: https://github.com/meganz/sdk/blob/master/CREDITS.md
MEGA SDK License: https://github.com/meganz/sdk/blob/master/LICENSE
MEGAcmd License: https://github.com/meganz/megacmd/blob/master/LICENSE
Features enabled:

  • CryptoPP
  • SQLite
  • inotify
  • fdopendir
  • FreeImage
  • PCRE
  • sync subsystem

Secondary effects

There were tests that moved a file to a folder where another file with the same name was present.
In Windows boths files were identified as one and when I ran a move instruction for that file
name it operated over the last moved file and left the oldest one in that folder. In Linux
both files are keep in the folder but identified as different ones, even if the properties where the
same; when a move operation was run over such filename it operated over both.

@polmr
Copy link
Collaborator

polmr commented May 16, 2018

That's very interesting issue.
The problem is that POSIX-compatible exit statuses are restricted to values 0-255, the range of an unsigned 8-bit integer (http://en.wikipedia.org/wiki/Exit_status)
We are returning negative number status. Either those mentioned from megacmd.h or the ones defined in class MegaError at megaapi.h (https://github.com/meganz/sdk/blob/develop/include/megaapi.h#L3683)
So, the negative signed values are stored in an unsigned 8-bit integer. This piece of code does the backwards conversion:

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
    uint8_t x = atoi(argv[1]);
    int8_t y = x;
    printf("%d\n", y);
}

In your particular case, 199 corresponds to MCMD_EARGS = -51.
In any case, we might want to change the return code to be always positive.

@polmr
Copy link
Collaborator

polmr commented May 16, 2018

Concerning the moving issue, @EliuX would you mind opening a separate issue with concrete example of what you are doing, so we can try to reproduce it?

@polmr
Copy link
Collaborator

polmr commented Sep 27, 2018

Exit status now are always positive to comply with POSIX standard. also, there's a new command "errorcode" that translate error number to some human readable explanation. Available in new version 1.0.0

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

No branches or pull requests

2 participants