xdebug ignoring error suppression - scream not installed - sublimetext3

I have xdebug installed and am developing using Sublimetext 3 on a Ubuntu 14.10 laptop. My issue is with errors that are suppressed using # symbol being parsed by xdebug. So any autoloaders in my neat mvc architecture means that I have to press the run shortcut keys repeatedly to eventually see if my changes worked or not. Very Irritating. Whats more so I do not have scream enabled. In my phpinfo() a search for scream only produces xdebug.scream = Off.
So... in my autoloaders the following will trigger warnings with xdebug.
#include $class . ".php";
Do I have to specifically tell xdebug to not ignore errors? Is there a way for me to programatically state that I want #include( warnings to be ignored by xdebug but include( warnings to be triggered?
any help is appreciated.
SublimeText 3 xdebug settings
{
// For remote debugging to resolve the file locations
// it is required to configure the path mapping
// with the server path as key and local path as value.
//
// Make sure to use absolute path when defining server path,
// because Xdebug debugger engine does not return symbolic links.
//
// Example:
// "/absolute/path/to/file/on/server" : "/path/to/file/on/computer",
// "/var/www/htdocs/example/" : "C:/git/websites/example/"
"path_mapping": {
},
// Determine which URL to launch in the default web browser
// when starting/stopping a session.
"url": "",
// An IDE key is used to identify with debugger engine
// when Sublime Text will start or stop a debugging session.
//
// This package does not filter sessions by IDE key,
// it will accept any IDE key, also ones that do not match this configured IDE key.
// It is merely used when launching the default web browser with the configured URL.
"ide_key": "",
// Which port number Sublime Text should listen
// to connect with debugger engine.
"port": 9000,
// Show super globals in context view.
"super_globals": true,
// Maximum amount of array children
// and object's properties to return.
"max_children": 32,
// Maximum amount of
// variable data to initially retrieve.
"max_data": 1024,
// Maximum amount of nested levels to retrieve
// of array elements and object properties.
"max_depth": 1,
// Break at first line on session start, when debugger engine has connected.
"break_on_start": false,
// Break on exceptions, suspend execution
// when the exception name matches an entry in this list value.
"break_on_exception": [
// E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR
"Fatal error",
// E_RECOVERABLE_ERROR (since PHP 5.2.0)
"Catchable fatal error",
// E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING
//"Warning"
],
// Always close debug windows and restore layout on session stop.
"close_on_stop": false,
// Do not show possible password values in context output.
"hide_password": false,
// Show in output parsed response instead of raw XML.
"pretty_output": false,
// Always launch browser on session start/stop.
// Note: This will only work if you have the 'url' setting configured.
"launch_browser": false,
// When launching browser on session stop do not execute script.
// By using parameter XDEBUG_SESSION_STOP_NO_EXEC instead of XDEBUG_SESSION_STOP.
"browser_no_execute": false,
// Do not use the debugging window layout.
"disable_layout": false,
// Window layout that is being used when debugging.
"debug_layout" : {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 0.7, 1.0],
"cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
},
// Group and index positions for debug views.
"breakpoint_group": 2,
"breakpoint_index": 1,
"context_group": 1,
"context_index": 0,
"stack_group": 2,
"stack_index": 0,
"watch_group": 1,
"watch_index": 1,
// Custom gutter icons for indicating current line or enabled/disabled breakpoints.
//
// Do not use same icon for following values, because Sublime Text is unable
// to use the same icon for different scopes, in case there are duplicate icons
// detected it will fall back to the corresponding icon in the package.
"breakpoint_enabled": "circle",
"breakpoint_disabled": "dot",
"breakpoint_current": "",
"current_line": "bookmark",
// Path to Python installation on your system.
// Which is being used to load missing modules.
//
// It is recommended to configure your Python path for Sublime Text 2
// especially on older UNIX systems, where some modules (xml.parsers.expat)
// might be missing and could improve performance of package.
//
// Example:
// "python_path" : "/usr/lib/python2.7"
"python_path" : "",
// Show detailed log information about communication
// between debugger engine and Sublime Text.
// Log can be found at Packages/User/Xdebug.log
"debug": false
}
And my project specific settings (just in case):
{
"folders":
[
{
"follow_symlinks": true,
"path": "/media/DATA/www/mysite.loc"
}
],
"settings": {
"xdebug": {
"url": "http://mysite.loc/",
}
}
}

I don't have sublime text, I'm a PhpStorm fan, so I can't verify anything for you. However, you should be able to add a break_on_exception configuration that doesn't include Notice, Warning, etc., and see if that works for you:
http://kerryritter.com/quickstart-guide-to-debugging-php-in-sublime-text-3/
"break_on_exception": [
// E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR
"Fatal error",
// E_RECOVERABLE_ERROR (since PHP 5.2.0)
"Catchable fatal error",
// // E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING
// "Warning",
// // E_PARSE
// "Parse error",
// // E_NOTICE, E_USER_NOTICE
// "Notice",
// // E_STRICT
// "Strict standards",
// // E_DEPRECATED, E_USER_DEPRECATED (since PHP 5.3.0)
// "Deprecated",
// // 0
// "Xdebug",
// // default
// "Unknown error"
],
[UPDATE 2015-03-06]
If your IDE is breaking on even suppressed errors, then I doubt that's an option. However, my suggestion would be to have it NOT break on any errors because you can see the errors in your error log with a tail very easily, and I don't think suppressed errors will go there. However, the fact that this is such a problem for you makes it sound like you are using error suppression for a LOT of errors...just my two cents, but this should never be the case.
http://www.sitepoint.com/why-suppressing-notices-is-wrong/
Even suppressed errors slow down the performance of your app...so if you using suppression to avoid testing for undefined indexes, etc. e.g.
$var = #$_POST['name']
Just to avoid doing this:
$var = isset($_POST['name']) ? $_POST['name'] : null;
Then, you should reconsider what you are doing and stop using suppression. For instance, it would be better to write a wrapper class:
class Input {
private $_input;
public function __construct( array $data ) {
$this->_input= $data;
}
public function get( $name ) {
return isset($this->_input[$name]) ? $this->_input[$name] : null;
}
}
Doing this not only keeps you from having to suppress errors, but makes your code more flexible and--not least to mention--able to be run by unit tests if the Input is injected.
$data = new Input($_POST);
$var = $data->get('name');

Related

How to use in each statement with mixed version dml devices?

Got a device with some common code in DML 1.4 where I want to verify a parameter is properly set on all fields of all registers by using and in each statement:
dml 1.4;
//import "each-bank.dml";
template stop_template {
param stop default true;
}
template dont_stop is stop_template{
param stop = false;
}
in each bank {
in each register {
in each field {
is stop_template;
#if (this.stop)
{
error "Stop here";
}
}
}
}
For a device in dml 1.2 my error statements triggers on d.o even if I add the template or parameter myself:
dml 1.2;
device each_device;
import "each-import.dml"
bank a {
register x size 4 #0x0 {
field alpha #[2:0] {
is dont_stop;
}
}
}
bank d {
register o size 4 #0x0 is stop_template;
}
DML-DEP each-device.dmldep
DEP each-device-dml.d
DMLC each-device-dml.c
Using the Simics 5 API for test-device module
/modules/test-device/each-device.dml:15:5: In d.o
/modules/test-device/each-import.dml:18:17: error: Stop here
...
gmake: *** [test-device] Error 2
Running the same code with an 1.4 device works as intended. Does the in each statement does not work with mixed devices?
Your issue is that in dml 1.2 registers with no declared fields get one whole-register-covering field implicitly defined by the compilator. This is then picked up by your each-statement, correctly.
To work around this, you need your template to check if it is actually being applied to an explicit field (part of the unfortunate pain that comes with writing common-code for both 1.2 and 1.4).
To do this: use the 1.2 parameter 'explicit' which is set by the compiler, which is 'true' for declared fields only. This parameter is however not present in 1.4, so you need to additionally guard this check with a check on the 'dml_1_2' parameter.
Something along the lines of:
in each bank {
in each register {
in each field {
// We cannot put this inside the hashif, despite wanting to,
// because DML does not (yet) allow conditional templating on
// parameters
is stop_template;
// This _does_ mean we can check this.stop first, saving us
// a little bit of code
#if (this.stop) {
// It is generally considered good practice to keep
// dml_1_2 checks in their own #if branch, so that they
// can be removed wholesale once 1.2 is no longer supported
#if (dml_1_2) {
#if (explicit) {
error "Stop here";
}
} #else {
error "Stop here";
}
}
}
}
}
In your case, the problematic code is a consistency check that's not strictly necessary for the device to function, so one option is to just skip this check for DML 1.2, assuming that most remaining DML 1.2 devices are legacy things where not much development is happening. So you can just put the problematic definitions inside #if (!dml_1_2) { } and it will compile again. Note that the compiler has a special case for the dml_1_2 parameter, which allows a top-level #if to contain any kind of top-level statement, including template definitions and typedefs.

Order of keys in package.json exports

I believe I understand the basic functioning of the exports key in package.json files:
// package.json
{
"exports": {
".": {
// used by typescript
"types": "./file_with_type_defs.d.ts",
// used by ESM resolution
"import": "./file_to_import.mjs",
// used by CJS resolution
"require": "./file_to_require.cjs",
// used by ...others?
"default": "./file_one_more.js"
}
}
}
Question: Does the order of the "types", "import", "require", and "default" keys matter? Normally I would think no way, since JSON object keys are unordered. From json.org:
An object is an unordered set of name/value pairs. An object begins with { ...
But Typescript documentation says that "types" must come first:
Entry-point for TypeScript resolution - must occur first!
"types": "./types/index.d.ts"
and the NodeJS documentation says "default" should come last
"default" - the generic fallback that always matches. Can be a CommonJS or ES module file. This condition should always come last.
So... Does the order of the export keys matter? If not, what do the NodeJS and Typescript documentation mean when they talk about "first" and "last"?
Having swapped the order of "types" with other keys, its order seems not to matter.
Webpack, which also uses the export key explains this field as follows:
Notes about ordering
In an object where each key is a condition, order of properties is significant. Conditions are handled in the order they are specified.
Rather than see this as a plain object, consider it being like this if-else case:
let file;
if (platform_supports('types')) {
file = "./file_with_type_defs.d.ts";
} else if (platform_supports('import')) {
file = "./file_to_import.mjs";
} else if (platform_supports('require')) {
file = "./file_to_require.cjs";
} else if (true) { // default
file = "./file_one_more.js";
}
If you were to swap the order, it might be like this:
let file;
if (true) { // default
file = "./file_one_more.js";
} else if (platform_supports('types')) {
file = "./file_with_type_defs.d.ts";
} else if (platform_supports('import')) {
file = "./file_to_import.mjs";
} else if (platform_supports('require')) {
file = "./file_to_require.cjs";
}
Even though Typescript understands .d.ts files it would use file_one_more.js since it matches first.
I have tried swapping the order of "types" with other keys. It seems not to matter.
It might be that Typescript prioritizes the types condition over others. However, I'd stick with what they advise—"must occur first" is not "ought to occur first", after all.
As a side-note, historically JavaScript object keys are unordered / the order is not guaranteed. In practice, browsers did preserve the key order and this behavior was standardized in ES2015: non-integer keys are preserved in insertion order.
The JSON standard doesn't make the same promise, as there are many implementations of JSON decoders in different languages and it the predates ES2015 standard.
JSON objects are "unordered set" as "key do not have a particular order(i.e. never have to be sorted)", not as "do not have an order"
Parsed JS object DOES have an order of keys matching the orger in JSON
Depending on if the code uses for (let k in json) or if (json.types) the behaviour may be different
So by whatever reason it's recommended to order keys in the way some parsers may expect
In your case I'd recommend you to try swapping them, seeing that nothing happens, and swapping them back

Cancel "allman" brace-style when 'implicit-arrow-linebreak' is "beside"

I was looking at similar issues, but it seems my case is somewhat special.
I'm wanting to enforce the "allman" brace-style, but also want to set the implicit-arrow-linebreak to "beside", as pictured:
{
// ...
"rules": {
"brace-style": [2, "allman"],
"implicit-arrow-linebreak": [2, "as-beside"],
// ...
}
// ...
}
Now I have this snippet:
this.fetchMeta()
.then(metadata => {
this.meta = metadata;
this.initiateInterval();
}).catch(this.destroy);
The first error I get is regarding the brace-style, which I understand can be fixed by creating a newline. Trying to fix this causes this error, making the this keyword unavailable (which I need). Declaring this as self before-hand does not work.
How do I cancel out the "allman" brace-style when implicit-arrow-linebreak is set to "beside"?

Different lint.xml for different build types in Android Studio?

I want to use different lint.xml files for release and debug build types in Android Studio. So, how can this be achieved?
When I place lint.xml in someModule/src/debug and someModule/src/release folders (also, these folders contain only that lint.xml file and nothing more) gradle reacts as there is no any lint.xml file, If I place single lint.xml file under core module folder (someModule/)- gradle recognizes it, but in this case I can't use different settings depending on build type...
Here's what worked for me:
tasks.whenTaskAdded { task ->
if (task.name.startsWith("lint")) {
if (task.name.toLowerCase().endsWith("release")) {
task.doFirst {
android.lintOptions.abortOnError = true
}
} else {
task.doFirst {
android.lintOptions.abortOnError = false
}
}
}
}
In my case I needed to turn on abortOnError for release builds so that I can develop freely but catch lint errors quickly on my CI (if they slipped).
I did not try it, but maybe something like this could help you.
tasks.whenTaskAdded { task ->
if (task.name == 'lintDebug') {
task.ext.lintXmlFileName = "lint-debug.xml"
} else if (task.name == 'lintDemo') {
task.ext.lintXmlFileName = "lint-demo.xml"
}
}
EDIT: comments feedback:
task.ext.xxxx is a custom name space for you to use: see https://docs.gradle.org/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
"lintXmlFileName" is a made up name. You won't find doc about it.
in android{... lintOptions {... lintConfig file("lint.xml")}} you need to read "lintXmlFileName" using ".ext.get("lintXmlFileName")" and set it for "lintConfig file()"
I did not test it, but I assume the "whenTaskAdded" goes outside of "android" in your app's build.gradle.
With kotlin build scripts (build.gradle.kts):
tasks.withType<LintBaseTask>().configureEach {
// doFirst is required else we get a Null Pointer Exception on lintOption
doFirst {
// This will override the lintOptions from the android extension
lintOptions.run {
if (name.toLowerCase().contains("debug")) {
// Do your configuration here
// isAbortOnError = true
// baselineFile = file("baseline.xml")
// isWarningsAsErrors = true
// isCheckDependencies = true
// ignore("MissingTranslation")
// setLintConfig(file("lint.xml"))
}
}
}
}
This is summary from Android studio new build system guide, lint support.
Lint support
As of version 0.7.0, you can run lint for a specific variant, or for all variants, in which case it produces a report which describes which specific variants a given issue applies to.
You can configure lint by adding a lintOptions section like following. You typically only specify a few of these; this section shows all the available options.
android {
lintOptions {
// set to true to turn off analysis progress reporting by lint
quiet true
// if true, stop the gradle build if errors are found
abortOnError false
// if true, only report errors
ignoreWarnings true
// if true, emit full/absolute paths to files with errors (true by default)
//absolutePaths true
// if true, check all issues, including those that are off by default
checkAllWarnings true
// if true, treat all warnings as errors
warningsAsErrors true
// turn off checking the given issue id's
disable 'TypographyFractions','TypographyQuotes'
// turn on the given issue id's
enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
// check *only* the given issue id's
check 'NewApi', 'InlinedApi'
// if true, don't include source code lines in the error output
noLines true
// if true, show all locations for an error, do not truncate lists, etc.
showAll true
// Fallback lint configuration (default severities, etc.)
lintConfig file("default-lint.xml")
// if true, generate a text report of issues (false by default)
textReport true
// location to write the output; can be a file or 'stdout'
textOutput 'stdout'
// if true, generate an XML report for use by for example Jenkins
xmlReport false
// file to write report to (if not specified, defaults to lint-results.xml)
xmlOutput file("lint-report.xml")
// if true, generate an HTML report (with issue explanations, sourcecode, etc)
htmlReport true
// optional path to report (default will be lint-results.html in the builddir)
htmlOutput file("lint-report.html")
// set to true to have all release builds run lint on issues with severity=fatal
// and abort the build (controlled by abortOnError above) if fatal issues are found
checkReleaseBuilds true
// Set the severity of the given issues to fatal (which means they will be
// checked during release builds (even if the lint target is not included)
fatal 'NewApi', 'InlineApi'
// Set the severity of the given issues to error
error 'Wakelock', 'TextViewEdits'
// Set the severity of the given issues to warning
warning 'ResourceAsColor'
// Set the severity of the given issues to ignore (same as disabling the check)
ignore 'TypographyQuotes'
}
}
EDIT: add the real and workable example
As we all know, the new Android build system is based on gradle. The core component of the gradle build system is task. There are different lint tasks if you project has different build variant. You can get those tasks from android studio All task list, or from commandline ./gradlew tasks. A example show as following, two build flavors demo and full.
lint - Runs lint on all variants.
lintDemoDebug - Runs lint on the DemoDebug build
lintDemoRelease - Runs lint on the DemoRelease build
lintFullDebug - Runs lint on the FullDebug build
lintFullRelease - Runs lint on the FullRelease build
These lint task are dependency on other tasks, here let's say preBuild.
Before run the lint task, it will run the task preBuild firstly. The task preBuild is an already existing task, but we can manipulate this pre-defined task and add more action to this task. android lintOptions property will be added and modified dynamically based on different build variants as the following code demonstrate in the file app/build.gradle.
preBuild.doFirst {
android.applicationVariants.each { variant ->
if (variant.name == 'demoDebug') {
println variant.name
android.lintOptions.quiet = true
android.lintOptions.lintConfig = new File('app/lint_demo_debug.xml')
// you can add more properties
} else if (variant.name == 'fullDebug') {
println variant.name
android.lintOptions.quiet = false
android.lintOptions.lintConfig = new File('app/lint_full_debug.xml')
// you can add more properties
} // more variants...
}
In order to run the code above successfully, the corresponding lint configuration file must exist under app directory.

Extending the YUI Panel

I have a requirement to extend the YUI Panel with some custom functionality that will be in a new file and shared across multiple views.
I am at a bit of a loss as to how best to go about this, can anyone give me any pointers please?
Let's say you want to extend a Panel to create one that has a list in its body. I usually use Y.Base.create for this. It's a more declarative way of extending YUI classes than using a constructor and Y.extend. But I'll stay closer to your example in the YUI forums.
There are a couple of tricks dealing with WidgetStdMod (one of the components of Y.Panel), but mostly it's just about using Y.extend and following the YUI inheritance patterns. I'll try to answer with an example:
function MyPanel() {
MyPanel.superclass.constructor.apply(this, arguments);
}
// hack: call it the same so you get the same css class names
// this is good for demos and tests. probably not for real life
MyPanel.NAME = 'panel';
MyPanel.ATTRS = {
listItems: {
// YUI now clones this array, so all's right with the world
value: []
},
bodyContent: {
// we want this so that WidgetStdMod creates the body node
// and we can insert our list inside it
value: ''
}
};
Y.extend(MyPanel, Y.Panel, {
// always a nice idea to keep templates in the prototype
LIST_TEMPLATE: '<ul class="yui3-panel-list"></ul>',
initializer: function (config) {
// you'll probably want to use progressive enhancement here
this._listContainer = Y.Node.create(this.LIST_TEMPLATE);
// initializer is also the place where you'll want to instantiate other
// objects that will live inside the panel
},
renderUI: function () {
// you're inheriting from Panel, so you'll want to keep its rendering logic
// renderUI/bindUI/syncUI don't call the superclass automatically like
// initializer and destructor
MyPanel.superclass.renderUI.call(this);
// Normally we would append stuff to the body in the renderUI method
// Unfortunately, as of 3.5.0 YUI still removes all content from the body
// during renderUI, so we either hack it or do everything in syncUI
// Hacking WidgetStdModNode is doable but I don't have the code around
// and I haven't memorized it
//var body = this.getStdModNode('body');
},
syncUI: function () {
// same here
MyPanel.superclass.syncUI.call(this);
// insert stuff in the body node
var listContainer = this._listContainer.appendTo(this.getStdModNode('body'));
Y.Array.each(this.get('listItems'), function (item) {
listContainer.append('<li>' + item + '</li>');
});
}
});

Resources