[GRASS-dev] Return value from g.copy is one when --overwrite - bug or feature?

When copying via g.copy and specifying --overwrite and the target object
already exists, the return value is 1 but no error message is returned:

,----
| simASM:grassAnalysis> g.copy --overwrite region=region1,region2
| simASM:grassAnalysis> echo $?
| 1
| simASM:grassAnalysis> g.version
| GRASS 7.0.1 (2015)
| simASM:grassAnalysis>
`----

From http://tldp.org/LDP/abs/html/exit-status.html:

,----
| A successful command returns a 0, while an unsuccessful one returns a
| non-zero value that usually can be interpreted as an error code.
`----

So shouldn't the return value be 0 in this case, as the command did what
it was told?

Cheers,

Rainer

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44

Fax (D): +49 - (0)3 21 21 25 22 44

email: Rainer@krugs.de

Skype: RMkrug

PGP: 0x0F52F982

Rainer,

I cannot seem to replicate your issue:

G srorg6630/tmp ~> g.version
GRASS 7.1.svn (2015)

G srorg6630/tmp ~> g.list region
tmp
tmp.d.rast.edit.6753
tmp1

G srorg6630/tmp ~> g.copy region=tmp,tmp1 --overwrite
Copy region definition tmp@tmp to current mapset as

G srorg6630/tmp ~> echo $?
0

g.copy returns 1 when it cannot either read the source or write to the target. Please check your permissions on your region files in LOCATION/MAPSET/windows/.

Regards,

Huidae

···

On Fri, Nov 6, 2015 at 8:21 AM, Rainer M Krug <Rainer@krugs.de> wrote:

When copying via g.copy and specifying --overwrite and the target object
already exists, the return value is 1 but no error message is returned:

,----
| simASM:grassAnalysis> g.copy --overwrite region=region1,region2
| simASM:grassAnalysis> echo $?
| 1
| simASM:grassAnalysis> g.version
| GRASS 7.0.1 (2015)
| simASM:grassAnalysis>
`----

From http://tldp.org/LDP/abs/html/exit-status.html:

,----
| A successful command returns a 0, while an unsuccessful one returns a
| non-zero value that usually can be interpreted as an error code.
`----

So shouldn’t the return value be 0 in this case, as the command did what
it was told?

Cheers,

Rainer


Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44

Fax (D): +49 - (0)3 21 21 25 22 44

email: Rainer@krugs.de

Skype: RMkrug

PGP: 0x0F52F982


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Huidae Cho <grass4u@gmail.com> writes:

Rainer,

I cannot seem to replicate your issue:

G srorg6630/tmp ~> g.version
GRASS 7.1.svn (2015)

G srorg6630/tmp ~> g.list region
tmp
tmp.d.rast.edit.6753
tmp1

G srorg6630/tmp ~> g.copy region=tmp,tmp1 --overwrite
Copy region definition <tmp@tmp> to current mapset as <tmp1>

G srorg6630/tmp ~> echo $?
0

g.copy returns 1 when it cannot either read the source or write to the
target. Please check your permissions on your region files in
LOCATION/MAPSET/windows/.

You are correct - they are read only.

So the return value is correct - but an error should be raised - or is
there a reason why this should silently fail?

Cheers,

Rainer

Regards,
Huidae

On Fri, Nov 6, 2015 at 8:21 AM, Rainer M Krug <Rainer@krugs.de> wrote:

When copying via g.copy and specifying --overwrite and the target object
already exists, the return value is 1 but no error message is returned:

,----
| simASM:grassAnalysis> g.copy --overwrite region=region1,region2
| simASM:grassAnalysis> echo $?
| 1
| simASM:grassAnalysis> g.version
| GRASS 7.0.1 (2015)
| simASM:grassAnalysis>
`----

From http://tldp.org/LDP/abs/html/exit-status.html:

,----
| A successful command returns a 0, while an unsuccessful one returns a
| non-zero value that usually can be interpreted as an error code.
`----

So shouldn't the return value be 0 in this case, as the command did what
it was told?

Cheers,

Rainer

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44

Fax (D): +49 - (0)3 21 21 25 22 44

email: Rainer@krugs.de

Skype: RMkrug

PGP: 0x0F52F982

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44

Fax (D): +49 - (0)3 21 21 25 22 44

email: Rainer@krugs.de

Skype: RMkrug

PGP: 0x0F52F982

On Sun, Nov 8, 2015 at 11:22 AM, Rainer M Krug <Rainer@krugs.de> wrote:

Huidae Cho <grass4u@gmail.com> writes:

Rainer,

I cannot seem to replicate your issue:

G srorg6630/tmp ~> g.version
GRASS 7.1.svn (2015)

G srorg6630/tmp ~> g.list region
tmp
tmp.d.rast.edit.6753
tmp1

G srorg6630/tmp ~> g.copy region=tmp,tmp1 --overwrite
Copy region definition <tmp@tmp> to current mapset as <tmp1>

G srorg6630/tmp ~> echo $?
0

g.copy returns 1 when it cannot either read the source or write to the
target. Please check your permissions on your region files in
LOCATION/MAPSET/windows/.

You are correct - they are read only.

So the return value is correct - but an error should be raised - or is
there a reason why this should silently fail?

It should probably not silently fail.

The code in question is in
lib/manage/do_copy.c

and potentially there to be added strerror(errno) as for example in
lib/gis/mapset_msc.c

?

Markus

Markus Neteler <neteler@osgeo.org> writes:

On Sun, Nov 8, 2015 at 11:22 AM, Rainer M Krug <Rainer@krugs.de> wrote:

Huidae Cho <grass4u@gmail.com> writes:

Rainer,

I cannot seem to replicate your issue:

G srorg6630/tmp ~> g.version
GRASS 7.1.svn (2015)

G srorg6630/tmp ~> g.list region
tmp
tmp.d.rast.edit.6753
tmp1

G srorg6630/tmp ~> g.copy region=tmp,tmp1 --overwrite
Copy region definition <tmp@tmp> to current mapset as <tmp1>

G srorg6630/tmp ~> echo $?
0

g.copy returns 1 when it cannot either read the source or write to the
target. Please check your permissions on your region files in
LOCATION/MAPSET/windows/.

You are correct - they are read only.

So the return value is correct - but an error should be raised - or is
there a reason why this should silently fail?

It should probably not silently fail.

Absolutely not - this can lead to errors as one assumes that no error
message means that the command was successful - I usually don't check
the return codes when I am working in a terminal.

The code in question is in
lib/manage/do_copy.c

and potentially there to be added strerror(errno) as for example in
lib/gis/mapset_msc.c

I don't know the inner workings of GRASS - but it looks like a good place?

On a related note - are the return codes documented somewhere (apart
From the source code)? OK - 0 is evident, but the others? They seem to
have specific meanings in GRASS?

Thanks,

Rainer

?

Markus

--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44

Fax (D): +49 - (0)3 21 21 25 22 44

email: Rainer@krugs.de

Skype: RMkrug

PGP: 0x0F52F982

Markus Neteler wrote:

It should probably not silently fail.

The code in question is in
lib/manage/do_copy.c

M_do_copy() returns a status. g.copy's main() checks that and uses it
to set the exit status, but it doesn't generate an error or warning if
the status is non-zero.

If G_recursive_copy() or M_do_copy() raised an error, that would
result in the program aborting on the first error; at present, it
copies as much as it can.

Realistically, g.copy() should be generating the error at the bottom
of main() if result is non-zero. E.g.

- exit(result);
+ if (result)
+ G_fatal_error(...);
+ return 0;

and potentially there to be added strerror(errno) as for example in
lib/gis/mapset_msc.c

That would require G_recursive_copy() to call G_warning() (with the
appropriate strerror(errno)) for each failed system call. Either that,
or G_recursive_copy() would have to generate a "log" of failures so
that the caller can report them.

--
Glynn Clements <glynn@gclements.plus.com>

r66775 adds a warning for non-vector elements as well.

···

On Mon, Nov 9, 2015 at 6:20 AM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

It should probably not silently fail.

The code in question is in
lib/manage/do_copy.c

M_do_copy() returns a status. g.copy’s main() checks that and uses it
to set the exit status, but it doesn’t generate an error or warning if
the status is non-zero.

If G_recursive_copy() or M_do_copy() raised an error, that would
result in the program aborting on the first error; at present, it
copies as much as it can.

Realistically, g.copy() should be generating the error at the bottom
of main() if result is non-zero. E.g.

  • exit(result);
  • if (result)
  • G_fatal_error(…);
  • return 0;

and potentially there to be added strerror(errno) as for example in
lib/gis/mapset_msc.c

That would require G_recursive_copy() to call G_warning() (with the
appropriate strerror(errno)) for each failed system call. Either that,
or G_recursive_copy() would have to generate a “log” of failures so
that the caller can report them.


Glynn Clements <glynn@gclements.plus.com>