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

Add sdh_die helper function--report an error message and exit #24017

Closed
embray opened this issue Oct 12, 2017 · 36 comments
Closed

Add sdh_die helper function--report an error message and exit #24017

embray opened this issue Oct 12, 2017 · 36 comments

Comments

@embray
Copy link
Contributor

embray commented Oct 12, 2017

As brought up in #23160, a lot of the spkg-install scripts define a helper function like this, so this adds one that they can share.

In many cases this won't even be needed because error messaging is already handled in the sdh_make helpers and the like. But occasionally it's still useful. This can be used like:

command || sdh_die "Error message"

much like the die command in perl.

Depends on #24092

Component: build

Author: Erik Bray

Branch/Commit: 6f7ed49

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/24017

@embray embray added this to the sage-8.1 milestone Oct 12, 2017
@embray
Copy link
Contributor Author

embray commented Oct 12, 2017

comment:2

Oops--accidentally pulled in some unrelated changes from #22509.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2017

Changed commit from be09dfc to 18e1757

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2017

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9da13d1Adds a handy sdh_die helper; rewrites existing helpers to use it
8f6ff3bAllow sdh_die, if run without arguments, to read an error message from stdin.
9085389Nicer: Automatically format the error message to the terminal width (or 80 chars by default)
f375a83With fmt, preserve existing line breaks, just wrap long lines
18e1757Use sdh_die for sdh_check_vars as well

@embray
Copy link
Contributor Author

embray commented Oct 12, 2017

comment:4

Cleaned up.

@embray
Copy link
Contributor Author

embray commented Oct 12, 2017

Dependencies: #24014

@embray
Copy link
Contributor Author

embray commented Oct 12, 2017

comment:5

This will conflict with #24014, so better to add that as a dependency and make the required changes here to make them compatible.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2017

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

4b87c10Get rid of the $PIP_INSTALL environment variable and replace it with a
56ad241Add some docs for this function
e5bebd1Keep PIP_INSTALL for now but quietly mark it as deprecated.
c69dfdaAdd error handling and SAGE_SUDO support for sdh_pip_install
9af9c98Adds a handy sdh_die helper; rewrites existing helpers to use it
3cd5b99Allow sdh_die, if run without arguments, to read an error message from stdin.
cf67bddNicer: Automatically format the error message to the terminal width (or 80 chars by default)
56de46eWith fmt, preserve existing line breaks, just wrap long lines
caf2698Use sdh_die for sdh_check_vars as well

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 12, 2017

Changed commit from 18e1757 to caf2698

@jdemeyer
Copy link

comment:8

The $(_sdh_cols) thing seems over-engineered to me. In particular, I have doubts about

echo "$msg" | fmt -s -w $(_sdh_cols)

because it means that we have to worry about the portability of the fmt program. I think it would be much better to just echo the message as-is. Also, there is a typo in a comment: 90 should be 80.

I like your sdh_die << _EOF_ trick but then that should be documented too at the top of sage-dist-helpers.

@jdemeyer
Copy link

Changed dependencies from #24014 to none

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:10

Replying to @jdemeyer:

The $(_sdh_cols) thing seems over-engineered to me.

That's fair in general :)

In particular, I have doubts about

echo "$msg" | fmt -s -w $(_sdh_cols)

because it means that we have to worry about the portability of the fmt program.

fmt is actually very portable, moreso even than grep. It's a sadly little-known, but very widely installed program and hasn't changed much over the ages. See for yourself--it's on OSX, openbsd, freebsd, pretty much any linux, and it's the same everywhere.

I'm not married to having it here, but I think the end result is nicer-looking error messages almost everywhere.

I think it would be much better to just echo the message as-is. Also, there is a typo in a comment: 90 should be 80.

I like your sdh_die << _EOF_ trick but then that should be documented too at the top of sage-dist-helpers.

Oh you're right--I thought i did write docs about that but apparently not.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Changed commit from caf2698 to c00425b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

50c1259Error message itself should also be output to stderr!
c00425bFix typo in comment; improve documentation.

@jdemeyer
Copy link

comment:12

Replying to @embray:

fmt is actually very portable, moreso even than grep. It's a sadly little-known, but very widely installed program and hasn't changed much over the ages. See for yourself--it's on OSX, openbsd, freebsd, pretty much any linux, and it's the same everywhere.

Fair enough. I give you the benefit of the doubt. It still feels over-engineered to me, but I won't block this ticket because of it.

Remember to set this back to needs_review when you are done.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:13

I don't disagree with the "over-engineered" assessment--there's more going on there than is needed for the bare-minimum functionality. But let's try it out for a bit. I think it is a nice little "quality of life" touch.

@jdemeyer
Copy link

comment:14

Concerning

If the last command run exited with an error,

Why this condition? It means that you couldn't do something like

if some_condition; then
    sdh_die "bla bla bla"
fi

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:15

This could be written something like

[ some_condition ] || sdh_die ...

though I realize in your example some_condition need not be the test command either.

Hmm--I think the original logic was that it was a failsafe of sorts; it would not "die" unless the previous command actually exited with an error. For example, although it's typically used with ||, if one ran command; sdh_die ... it would only "die" if the command returned a non-zero exit status.

But maybe sometimes you'd also want to "die" if some command succeeded. So I think ultimately this restriction is not well-justified. I'll remove it.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Changed commit from c00425b to 43e618a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

43e618adifferent logic for handling error codes: sdh_die always returns non-zero, but if the previous exit

@jdemeyer
Copy link

comment:17

In

if [ $ret -ne 0 ]; then

did you mean

if [ $ret -eq 0 ]; then

@embray
Copy link
Contributor Author

embray commented Oct 26, 2017

comment:18

Replying to @jdemeyer:

In

if [ $ret -ne 0 ]; then

did you mean

if [ $ret -eq 0 ]; then

Yes, thank you for catching that.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

883df11Use the correct comparison here

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2017

Changed commit from 43e618a to 883df11

@embray
Copy link
Contributor Author

embray commented Oct 26, 2017

comment:20

Is there a good place to put miscellaneous tests that aren't for an actual module in the sage package? Under src/sage/tests, maybe?

I would like to add a test suite for these functions (in a separate ticket).

@jdemeyer
Copy link

comment:21

Replying to @embray:

Under src/sage/tests, maybe?

Since it's about building Sage, it would better be in src/sage_setup.

@embray
Copy link
Contributor Author

embray commented Oct 26, 2017

comment:22

There's not a sage_setup.tests package yet to speak of, but I guess there could/should be.

@jdemeyer
Copy link

comment:23

Works for me.

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

@embray
Copy link
Contributor Author

embray commented Oct 27, 2017

comment:24

FWIW the recent patchbot failure is due to the issue fixed by #24092, though it might be good the make that a dependency of this...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 27, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

6dd69fdAdd pip to brial's dependencies, replace the use of PIP_INSTALL as per #24014.
6f7ed49Merge branch 'u/fbissey/brial_pip' into u/embray/build/sdh_die

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 27, 2017

Changed commit from 883df11 to 6f7ed49

@embray
Copy link
Contributor Author

embray commented Oct 27, 2017

Dependencies: #24092

@embray
Copy link
Contributor Author

embray commented Oct 27, 2017

comment:26

Added #24092 as a dependency in the hopes of getting better patchbot feedback.

@jdemeyer
Copy link

comment:27

Replying to @embray:

Added #24092 as a dependency in the hopes of getting better patchbot feedback.

Does the patchbot even look at the dependencies?

@embray
Copy link
Contributor Author

embray commented Oct 27, 2017

comment:28

I don't think so, but it still makes sense to track doesn't it?

(I am also trying to update the trac plugin to better diff branches against their dependencies, but that's a moot point for now...)

@vbraun
Copy link
Member

vbraun commented Oct 30, 2017

Changed branch from u/embray/build/sdh_die to 6f7ed49

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

3 participants