Giter Club home page Giter Club logo

hack-error-suppressor's Introduction

INACTIVE PROJECT

THIS PROJECT IS NO LONGER ACTIVE; it is not needed with HHVM 3.25 and later.

Hack Error Suppressor Build Status

Unless the hhvm.hack.lang.look_for_typechecker ini setting is set to false, by default HHVM will try to run the typechecker when loading any Hack files, and raise a catchable runtime fatal error.

This is a PHP library that makes it convenient to temporarily disable this behavior.

When This Is Useful

HHVM's behavior is problematic when:

  • HHVM can't work out where the project root is - for example, if you're trying to run Hack code from a composer plugin
  • If your Hack code needs to operate on an incomplete project - for example, if you wish to write Hack code to fetch dependencies
  • If your Hack code needs to operate on known-bad projects - for example, when updating generated code, the code may be inconsistent while your codegen is in process

When You Shouldn't Use This

It's probably not appropriate if any of these are true:

  • it's used outside of a build/install or codegen process
  • it's used when using generated code
  • it's called during normal use of your software, rather than just by developers
  • it's used outside of the CLI

Typechecker errors are real problems with code, and mean that things are broken; ignoring enforcement is only a good idea if you are expecting your code to be running on a temporarily-broken codebase, and your code fixes it.

Installation

$ composer require fredemmott/hack-error-suppressor

Usage

You must enable error suppression before any Hack code is loaded.

You can explicitly enable and disable the suppression:

<?php
use FredEmmott\HackErrorSuppressor;

$it = new HackErrorSuppressor();
$it->enable();
call_some_hack_code();
$it->disable();

You can also enable the suppression with a scope:

<?php

use FredEmmott\ScopedHackErrorSuppressor;

function do_unsafe_stuff() {
  $suppressor = new ScopedHackErrorSuppressor();
  call_some_hack_code(); // this works
}

do_unsafe_stuff();
call_some_hack_code(); // this fails, as we're out of scope

Using Outside Of The CLI

This is disallowed by default; if you're absolutely certain you need to do this (keeping in mind that typechecker errors are real problems with your code, not just lint) you can disable the check:

FredEmmott\HackErrorSuppressor::allowRealRequestsAgainstBrokenCode();

hack-error-suppressor's People

Contributors

fredemmott avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

acrylic-origami

hack-error-suppressor's Issues

HackErrorSuppressor doesn't suppress in HHVM 3.19.1

It seems that somewhere between HHVM 3.18.3 and 3.19.1, the backtrace for a Hack typechecker error changed. The first entry in the backtrace passed to the custom error handler no longer always points to a function call, so the function field isn't always set.

With a minimal project setup:

hh_autoload.json:
{ "roots": ["src/"] }

composer.json:
{
	"require": {
		"facebook/hhvm-autoload": "dev-master"
	}
}

In 3.19.1, the first entry of the backtrace is:

array(2) {
  ["file"]=>
  string(88) "/path/to/project/root/vendor/facebook/definition-finder/autoload_files.php"
  ["line"]=>
  int(21)
}

In contrast to 3.18.3:

array(4) {
  ["file"]=>
  string(88) "/path/to/project/root/vendor/facebook/definition-finder/autoload_files.php"
  ["line"]=>
  int(21)
  ["function"]=>
  string(29) "HH\Client\typecheck_and_error"
  ["args"]=>
  array(0) {
  }
}

Without the function field set, the error handler lets the "Error: could not find a .hhconfig file..." error pass through it.

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.