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

--skip and --fail options for handling HTTP 4xx and 4xx errors #102

Closed
simonw opened this issue Jan 28, 2023 · 5 comments
Closed

--skip and --fail options for handling HTTP 4xx and 4xx errors #102

simonw opened this issue Jan 28, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jan 28, 2023

The script that updates https://simonw.github.io/datasette-screenshots/ has a problem: occasionally it takes a screenshot that looks like this:

image

I don't want to manually check the shots every time I the GitHub Actions runs, so I'd like to have an option for shot-scraper multi that can spot if a page comes back with a non-200 error and logs a warning but keeps going.

That way any failures in that repo at least won't over-write a good screenshot.

@simonw simonw added the enhancement New feature or request label Jan 28, 2023
@simonw
Copy link
Owner Author

simonw commented Jan 28, 2023

This should probably be accompanied by an option that causes the entire script to quit with an error status code (such that CI will fail) if a 4xx or 5xx is encountered.

@simonw
Copy link
Owner Author

simonw commented Jan 28, 2023

Asked ChatGPT:

What are some good names for an option for a CLI script which means "fail with a non-zero exit code if an HTTP error occurs"

It came up with some bad options, so I asked:

Are there any commands like "curl" that have an option like this? List the commands and their options

Got back:

Yes, there are several commands like curl that have an option to fail with a non-zero exit code when an HTTP error occurs. Some examples include:

  • curl: -f, --fail
  • wget: --no-clobber
  • httpie: --fail
  • http (from httpie): --fail

These commands also have --silent,--show-error, -S options which make them not output anything to stdout, these options also make them fail with a non-zero exit code if an HTTP error occurs.

I'm going to go with --fail.

@simonw simonw changed the title Option with multi to skip screenshots of pages that return errors --skip and --fail options for handling HTTP 4xx and 4xx errors Jan 28, 2023
@simonw
Copy link
Owner Author

simonw commented Jan 28, 2023

I'm going to add --skip and --fail to the shot-scraper shot and shot-scraper multi commands.

Should I add them to pdf and html and accessibility and javascript as well?

I'm leaning towards "yes", because each of those commands might be used like so:

shot-scraper pdf https://unreliable-website.com/ -o latest.pdf

And people may want to overwrite latest.pdf only if the web page is up.

@simonw
Copy link
Owner Author

simonw commented Jan 30, 2023

Demo:

% echo '- url: https://latest.datasette.io/404' | shot-scraper multi - --fail
Error: 404 error for https://latest.datasette.io/404
% echo $?
1
% echo '- url: https://latest.datasette.io/404' | shot-scraper multi - --skip
404 error for https://latest.datasette.io/404, skipping
% echo $?                                                                    
0

@simonw
Copy link
Owner Author

simonw commented Jan 30, 2023

More demos:

% shot-scraper html https://simonwillison.net/404 --skip
404 error for https://simonwillison.net/404, skipping
% echo $?
0
% shot-scraper html https://simonwillison.net/404 --fail
Error: 404 error for https://simonwillison.net/404
% echo $?
1

% shot-scraper javascript https://simonwillison.net/404 'document.title' --skip
404 error for https://simonwillison.net/404, skipping
% echo $?
0
% shot-scraper javascript https://simonwillison.net/404 'document.title' --fail
Error: 404 error for https://simonwillison.net/404
% echo $?
1

% shot-scraper pdf https://simonwillison.net/404 --skip
404 error for https://simonwillison.net/404, skipping
% echo $?
0
% shot-scraper pdf https://simonwillison.net/404 --fail
Error: 404 error for https://simonwillison.net/404
% echo $?                                              
1

% shot-scraper accessibility https://simonwillison.net/404 --skip
404 error for https://simonwillison.net/404, skipping
% echo $?
0
% shot-scraper accessibility https://simonwillison.net/404 --fail
Error: 404 error for https://simonwillison.net/404
% echo $?                                                        
1

@simonw simonw closed this as completed in 66181e9 Jan 30, 2023
simonw added a commit that referenced this issue Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant