GithubHelp home page GithubHelp logo

panosru / fault-manager Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 170 KB

A convinient way for exception handling and generating on the fly non-existing exceptions.

Home Page: http://fault-manager.readthedocs.io/

License: MIT License

PHP 91.12% Shell 8.88%

fault-manager's Introduction

Fault Manager

A convinient way for exception handling and generating on the fly non-existing exceptions.

version Build Status Code Coverage StyleCI Scrutinizer Code Quality Documentation Status MIT License

All Contributors PRs Welcome Code of Conduct downloads Watch on GitHub Star on GitHub Tweet

Installing

composer require panosru/fault-manager

~ Read the docs to get started.

Contributing & Code of Conduct

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Panagiotis Kosmidis (AKA @panosru)

See also the list of contributors who participated in this project.

Built With

Acknowledgment

License

This project is licensed under the MIT License - see the LICENSE file for details

fault-manager's People

Contributors

panosru avatar alextech avatar

Stargazers

 avatar  avatar

Watchers

 avatar James Cloos avatar

fault-manager's Issues

Force regenerate an exception

Sometimes, for whatever reason, you may need to re-generate a previously generated custom exception. Currently, that is not available, and in case you need to regenerate an exception you'll have to manually delete it.

I believe that a 6th argument in Fault::exception() and Fault::throw() should be introduced that would allow you to force the regeneration of that particular exception.

So you would have a syntax like this:

Fault::throw(
    'MyCustomException',
    'hello %s',
    0,
    null,
    ['world'],
    true
);

And that would generate the file again even if is previously generated already.

Compile generated classes

Currently, custom exceptions are generated with the use of Mockery.

If EventStream is enabled, then unfortunately because of mockery/mockery#534 issue, we cannot mock an exception with a custom name.

If instead of Mockery we compile the classes into files, then two issues will be resolved.

  1. We can have custom named classes with the support of EventStream
  2. IDE won't complain about missing classes when we use for example $customException instanceof \MyCustomGeneratedException

Event Handlers

If you enable EventStream, then your custom exceptions will extend from FaultManagerException abstract class which uses Hoa\Exception & Hoa\Event libs, allowing you to attach an event handler to your exceptions.

Still problem with file system.

  1. Getting same error with latest flysystem in actual project

default

Attempted usage:

throw Fault::exception(\Importer\ImporterException::class, 'Problem selecting sheet', 1002, $e);
  1. It is writing to _compiled under omegad-biz. That is a problem, because hosts will not have write permissions there. Write permissions will be often given manually to designated directory, such as data at top level.

Global force regeneration

In addition to #10 a global force regeneration flag should be introduced in order to force the regeneration of all previously generated custom exceptions.

Fault::exception does not work as factory alone, seems to actually throw exception

Here I am "converting" exception from a different library to a custom exception so I know semantically what happened

try {
   $worksheet = $spreadsheet->getSheet(5);
   } catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
   throw Fault::exception(\ImporterException::class, 'Problem selecting sheet', 1002, $e);
}

This results in

ImporterException : Problem selecting sheet
\vendor\omegad-biz\fault-manager\src\Fault.php:109
\src\Importer\src\Importer.php:123
\test\ImporterTest\ImporterTest.php:38

Exception is coming from within library, not my code. Assuming this is a bug, because Fault::throw is supposed to have this behavior, while Fault::exception should act as a factory

Pass configuration array into FaultManager

I was thinking of creating a method that would accept an array of configuration, something like public void \Omega\FaultManager\Fault::setConfig ( array $config )

There are many uses cases where that could be useful, few that I can think now are:

  • set current environment
  • have specific options per environment
  • add predefined lists of custom exceptions so FaultManager would pre-compile them
  • predefined configurations will be compiled with message and code already in their code
  • set flags
    • force recompile option
    • enable Fault EventStream by default
    • custom compile path
  • define handlers for events (each event exception is an event)

Any other suggestion is welcome

Some issues with bin/fault-manager and composer scripts

I'm not expert in bash scripting, thus some help is needed to address some issues with the executable script of that project.

I have defined some scripts in composer.json where I invoke the bin/fault-manager bin
https://github.com/omegad-biz/fault-manager/blob/7ba0ab5ab1ffa7070771ace9630075b3776f75c1/composer.json#L41-L60

Bellow is the terminal output when running directly from bin/fault-manager and when running via composer

$ bin/fault-manager
fault-manager [COMMAND]

Description of this script.

 Options:
  -t, --tests               Run tests without coverage
  -T, --tests-coverage      Run tests with coverage
                            this through the interactive option
  -c, --clear               Clears _compile/ folder
  -C, --clear-tests         Clears tests/_compile/
  -X, --clear-all           Clear both _compile/ and
                            tests/_compile/ folders
  -f, --force               Skip all user interaction
  -i, --interactive         Prompt for values
  -q, --quiet               Quiet (no output)
  -v, --verbose             Output more
  -h, --help                Display this help and exit
      --version             Output version information and exit

$ bin/fault-manager -t and $ bin/fault-manager -T run as expected.

When I run $ bin/fault-manager -c or $ bin/fault-manager -C or $ bin/fault-manager -X if _compile/ and/or tests/_compile/ folders are empty then I receive:

find: _compiled/*: No such file or directory
find: tests/_compiled/*: No such file or directory

How can I mute that? I tried to put &> /dev/null after lines 103 and 106 but it doesn't help...
https://github.com/omegad-biz/fault-manager/blob/7ba0ab5ab1ffa7070771ace9630075b3776f75c1/bin/fault-manager#L99-L113

The other issue I have is when I run composer scripts for instance, composer compiled-clear is equivalent to bin/fault-manager -c, but when I run with composer I'm receiving error exit 1.

$ touch _compiled/SomeDommyFile.php
$ composer compiled-clear
> bin/fault-manager -c

Script bin/fault-manager -c handling the compiled-clear event returned with error code 1

The compiled folder is now empty, so the script did its job, but composer returns with error code 1 and I'm not sure why...

another issue is when I run composer test, it simply not working at all... :(

$ composer test
> bin/fault-manager -C
find: tests/_compiled/*: No such file or directory

Script bin/fault-manager -C handling the compiled-clear-tests event returned with error code 1

If anyone could provide some support it would be much appreciated!

Thank you in advance!

interpolate exception message with arguments

Currently, if you enable Fault EventStream then your custom generated exceptions will be able to have a syntax like the following:

Fault::enableEventStream();
Fault::throw(
    'MyCustomException',
    'hello %s',
    0,
    null,
    ['world']
);

So the message on the above exception will result in hello world

but if you have not enabled Fault EventStream the last parameter $arguments which on the example is ['world'] will be ignored, thus your message will be hello %s.

I believe that even if the custom exception is not a Fault EventStream exception, it should still benefit from that functionality, so you could have something like this:

Fault::throw(
    \Exception::class,
    'hello %s',
    0,
    null,
    ['world']
);

and your message should result into hello world

Custom namespaces for custom exceptions?

I'm still thinking about that.

Currently, all generated exceptions are in the global namespace.

So if you run Fault::exception('MyCustomException'); it will result in \MyCustomException.

Is not a hard implementation, but I'm yet to come up if is a good idea.

Also what you prefer?

  1. Fault::exception('\CustomNamespace\MyCustomException');
  2. Fault::exception('CustomNamespace\MyCustomException'); (without the leading backslash)
  3. Fault::exception('MyCustomException', <message>, <code>, <previous>, <arguments>, 'CustomNamespace');
    3.1 Fault::exception('MyCustomException', null, null, null, null, 'CustomNamespace');

I don't like the 3rd way 😵

@alextech any thoughts?

Autoloading bug

When installed the following error is thrown

Warning: require(/path/omega/fault-manager/vendor/composer/../../src/Autoloader.php): failed to open stream: No such file or directory

...

Fatal error: require(): Failed opening required '/path/omega/fault-manager/vendor/composer/../../src/Autoloader.php'

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.