Code Monkey home page Code Monkey logo

grav-plugin-error's Introduction

Grav Error Plugin

GPM Installation

error is a Grav Plugin and allows to redirect errors to nice output pages.

This plugin is included in any package distributed that contains Grav. If you decide to clone Grav from GitHub you will most likely want to install this.

Installation

Installing the Error plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:

bin/gpm install error

This will install the Error plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/error.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to error. You can find these files either on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/error

NOTE: This plugin is a modular component for Grav which requires Grav, the Problems plugin, and a theme to be installed in order to operate.

Usage

The error plugin doesn't require any configuration. The moment you install it, it is ready to use.

Something you might want to do is to override the look and feel of the error page, and with Grav it is super easy.

Template

Copy the template file error.html.twig into the templates folder of your custom theme and that is it.

/your/site/grav/user/themes/custom-theme/templates/error.html.twig

You can now edit the override and tweak it however you prefer.

Page

Copy the page file error.md into the pages folder of your user directory and that is it.

/your/site/grav/user/pages/error/error.md

You can now edit the override and tweak it however you prefer.

Custom error pages

The configuration allows to specify pages different than /error for specific error codes. By default, the 404 error leads to the /error page. If you change that, make sure the page you point to has a error template (which means, its markdown file is error.md or in the page frontmatter you specify template: error.

CLI Usage

The error plugin comes with a CLI command that outputs the grav.log in a beautified way, with possibility of limiting the amount of errors displayed, as well as include the trace in the output.

Commands

bin/plugin error log
[ --limit N | -l N ] The amount of errors to display. Default is 5
[ --trace | -t ] When used, it will add the backtrace in the output of the error

Updating

As development for the Error plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Error is easy, and can be done through Grav's GPM system, as well as manually.

GPM Update (Preferred)

The simplest way to update this plugin is via the Grav Package Manager (GPM). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:

bin/gpm update error

This command will check your Grav install to see if your Error plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type y and hit enter. The plugin will automatically update and clear Grav's cache.

Manual Update

Manually updating Error is pretty simple. Here is what you will need to do to get this done:

  • Delete the your/site/user/plugins/error directory.
  • Download the new version of the Error plugin from either GitHub or GetGrav.org.
  • Unzip the zip file in your/site/user/plugins and rename the resulting folder to error.
  • Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing bin/grav clear-cache.

Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in user/config/plugins) will remain intact.

grav-plugin-error's People

Contributors

aender6840 avatar dommyet avatar fbrnc avatar flaviocopes avatar fm avatar gour avatar hermes-diactoros avatar j000 avatar johnmica avatar lufog avatar mahagr avatar perlkonig avatar rbukovansky avatar rhukster avatar ricardo118 avatar ryanmpierson avatar w00fz avatar zeegin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grav-plugin-error's Issues

Sitemap header shows 404

I'm realizing now that setting the header (see pull request #1) has a side effect: The sitemap plugin is also returning a status code 404 now. I guess even though the sitemap is hijacking the output (don't know exactly how it hook into the request lifecycle), Grav still tries to render a page, won't fine it, triggers the error plugin and sets the 404 header.

Not sure how to proceed, but the main problem seems to be that in case onPageNotFound event shouldn't be fired in case of the sitemap.

Configuration options and hints

Thx for this plugin.

I've created an issue for the GRAV admin plugin: Issue. This issue affects the popularity counters exposed in the dashboard of the admin plugin. To solve these issues I propose to implement the following:

A hint that makes clear that a personalized error page needs to use specific templates (right now only templates with the name "error" are totally supported)

That's not really a bug but it's important because statistics are important.

Broke upon update

I updated the plugin and it is no longer functional.

  • I followed the directions regarding the new /pages/error/error.md file
    • Not sure I love this feature
  • Also reverted my custom template to exactly match the default template in the plugin folder

..but it is still broken in exactly the same way.

This is the dump (there is no & in my error.md file):

Twig_Error_Syntax thrown with message "Unexpected character "&" in "@Page:/var/www/public_html/devsites/hrtc/user/pages/error" at line 1."

Stacktrace:
#20 Twig_Error_Syntax in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Lexer.php:284
#19 Twig_Lexer:lexExpression in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Lexer.php:216
#18 Twig_Lexer:lexVar in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Lexer.php:115
#17 Twig_Lexer:tokenize in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Environment.php:581
#16 Twig_Environment:tokenize in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Environment.php:671
#15 Twig_Environment:compileSource in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Environment.php:396
#14 Twig_Environment:loadTemplate in /var/www/public_html/devsites/hrtc/vendor/twig/twig/lib/Twig/Environment.php:347
#13 Twig_Environment:render in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Twig/Twig.php:242
#12 Grav\Common\Twig\Twig:processPage in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Page/Page.php:702
#11 Grav\Common\Page\Page:processTwig in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Page/Page.php:591
#10 Grav\Common\Page\Page:content in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Twig/Twig.php:319
#9 Grav\Common\Twig\Twig:processSite in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Service/OutputServiceProvider.php:19
#8 Grav\Common\Service\OutputServiceProvider:Grav\Common\Service\{closure} in /var/www/public_html/devsites/hrtc/vendor/pimple/pimple/src/Pimple/Container.php:113
#7 Pimple\Container:offsetGet in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Processors/RenderProcessor.php:17
#6 Grav\Common\Processors\RenderProcessor:process in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:121
#5 Grav\Common\Grav:Grav\Common\{closure} in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:383
#4 Grav\Common\Grav:Grav\Common\{closure} in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:359
#3 call_user_func_array in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:359
#2 Grav\Common\Grav:__call in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:122
#1 Grav\Common\Grav:measureTime in /var/www/public_html/devsites/hrtc/system/src/Grav/Common/Grav.php:122
#0 Grav\Common\Grav:process in /var/www/public_html/devsites/hrtc/index.php:45

Default onPageNotFound priority should be -1 or less.

Default onPageNotFound priority should be -1 or less.

This will allow other plugins to set the priority to 0 on onPageNotFound and still be called when they are loaded after the default fallback of this plugin.

Lacks spanish translation

Here is it;

es:
__PLUGIN_ERROR:
____ERROR: "Error"
____ERROR_MESSAGE: "Ups. Parece que esta página no existe."

cli command `bin/plugin error log` sintax error

Hi,

I am trying to test here the bin/plugin error log cli command, but getting this error:

Parse error: syntax error, unexpected '.', expecting ',' or ';' in plugins://error/cli/LogCommand.php on line 18
Whoops\Exception\ErrorException: syntax error, unexpected '.', expecting ',' or ';' in file plugins://error/cli/LogCommand.php on line 18
Stack trace:
  1. () plugins://error/cli/LogCommand.php:18

is about this line:

protected $logfile = LOG_DIR . 'grav.log';

my cli php -v is: PHP 5.5.30

Unauthorized

upon clicking on Update plugin from v 1.3.0. I get an error Unauthorized

Intentional Routes to Error Pages

Hey All,

Are there any built-in routes for purposefully triggering specific error pages? I'd like to tweak the default .htaccess file to rewrite URLs for sensitive files (e.g., dotfiles) so that the 404 page is displayed. Currently, the .htaccess file does a 301 redirect to /error, which leaks information on whether or not a file exists on the filesystem (redirect? it exists. no redirect? it does not exist). In either case, the HTTP response status is 404 (instead of, for example, 403 Forbidden), which is good, but I'd like my 404s to be consistent in not redirecting users away from the URL they originally accessed.

I've found that I can simply rewrite the URL to index.php and it will trigger the Grav 404 page for these files. Is this solution ideal/adequate, or are there possible edge cases that will produce inconsistent results? Is there another solution entirely? Though my use case at the moment is really only concerned with explicitly routing to the 404 page, would it make sense to support routing to any HTTP error status code page?

Regards,
--- Scott

EDIT: After looking into this more, it seems like the current behavior actually differs depending on platform. For example, the .htaccess file does cause a 403 Forbidden to occur, while the web.config file causes a redirect to /error which responds with a 404. Regardless, my end goal is to always return a 404 and never redirect.

"Page not Found" title in different languages

Hello!

Today I found that in every language my title looks the same:

Page not Found — sitename

Maybe need to put +1 line to languages.yaml:

PLUGIN_ERROR:
    ERROR: "Error"
    ERROR_MESSAGE: "Woops. Looks like this page doesn't exist."
    ERROR_TITLE_404: "Page not found"

and correctly handle this?

About error page title translation

I reopen an issue concerning the translation of the title of the error pages.

Indeed, an issue about the translation of the page title string was opened previously in 2016 by @Sogl (cf. #23) but was closed in 2018.

The pull request which had been envisaged by @rbukovansky (cf. #26) doesn't seem to have been finally retained (it was reverted by @rhukster in e06ca06).

However, the issue seems still unsolved at the moment or maybe I missed the key solution to properly translate this page.title variable within an error page...

PS : Of course, you may directly close this present issue and reopen the previous one if you consider the original issue as still relevant.

Feature request: forward 404 to server

I know the plugin is "required", but I'd like to be able to customize the 404 reaction - in a nutshell, I would like it to be able to let the server handle the 404, so that the server can redirect a nonexistent post to my old blog, which is on a different subdomain now. Can this be done easily?

Refactor error.md and .twig to default?

I just spent an hour trying to understand why the PLUGIN_ERROR:ERROR translation had no effect on out-of-box grav installation. As it turned out, Quark (default theme) overrides error.html.twig with its own, which uses different variable (ERROR).
So here is my issue:
Both grav-plugin-error and quark theme (i know there are more..) define h1 header in the twig files. Error page itself is not defined in theme, but exists in (mandatory) error plugin. This creates situation, where single functionality (showing error message content) is divided into two different places with conflicting translations. This will be the same for other themes as well, as the plugins error.html.twig is too basic to be useful without theme overriding it, which means the theme twig needs to define h1 again.

Maybe I am missing something obvious here, but I do not see real benefit in having in plugin error template and error page over having default.md page and allowing theme default template render it. If user needs to define separate template for error pages or start using the theme provided one, they could easily create /error/error.md and set template there.

So, what i suggest for both quark theme and plugin-error:

  1. rename plugins error.md to default.md (including php change)
  2. move h1 header from plugin error.html.twig to default.md
  3. remove plugins error.html.twig completely (expect theme to have default template)
  4. in quark error.html.twig remove h1 header (or remove error.html.twig completely, as it is no different from default) and allow error plugin OR custom error page provide page content.

1-3 are not breaking changes toward out-of-box installation, but may break other themes that have worked around the need to provide error page header themselves.

Alternatively, the translation could be explained in the readme more clearly..
Thoughts?

Failed to save entry: Flex saveRow

Hello,
Im having this issue and cannot upload any changes to my site. Anyone had same ?

Creating directory failed for /srv/disk25/4****/www/madeinmaurice.net/tmp/forms/3e***4babd56f81e4ececa/8d6df7892fb6b656fb8ed41b3/index.yaml

Failed to save file /srv/disk25/4****/www/madeinmaurice.net/user/pages/02.all-bookies-and-live-scores/default.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.