gulp-notify - get file name, not whole path, with error - error-handling

I'm using gulp-notify and gulp-plumber to catch any errors from gulp-sass and notify me before it throws an error in gulp and stops the whole build process. However, the error shown with gulp-notify isn't particularly helpful...it contains the whole path to the file with the error; I will most likely know what the path to the file is, so I only really to need know the file name and line number (and column number as an added but not necessary bonus), and also the actual error message.
Here is my code:
gulp.task('styles', function () {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Build Error!",
message: "<%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
gulp.src('assets/styles/source/style.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass({
style: 'compressed',
errLogToConsole: false
}))
.pipe(gulp.dest('assets/styles/build'))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie 9', 'ios 6', 'android 4'],
cascade: false
}))
.pipe(gulp.dest('assets/styles/build'))
.pipe(minifyCSS({
keepSpecialComments: '*'
}))
.pipe(gulp.dest('./'))
.pipe(reload({stream: true}));
});
There's more (like gulp-watch, browsersync, some JS stuff) but I think the above is all that's needed to solve the issue. Let me know if not!
So my question is, how do I modify the error message to only show me the file name, line number and error message (e.g _header.scss:17 - invalid property name)? Currently I'm using error.message but I can't find any more tags I can use to get the things I want to show.
Thank you!

Here's how I solved that problem:
.pipe(sass(
({
style: 'compressed',
errLogToConsole: false,
onError: function(error) {
notify({
title: "SASS ERROR",
message: "line " + error.line + " in " + error.file.replace(/^.*[\\\/]/, '') + "\n" + error.message
}).write(error);
}
})
)
)
I also noticed that I'm only able to provide one line break "\n" so I wasn't able to split each piece of information I wanted on its own line.

Related

"after all" hook error while running test

This is my test body:
/// <reference types = "cypress" />
it('Testing story book button primary', function(){
cy.visit('https://storybook.prod.ublox-website.ch4.amazee.io/iframe.html?id=components-button--primary&viewMode=story')
cy.wait(1000)
cy.eyesOpen({
appName: 'Story book',
testName: 'check button primary',
});
cy.eyesCheckWindow();
cy.eyesClose();
});
I have attached a screenshot of my error at the end it displays this error( I have attached).
Can someone please let me know why I am getting this error? I am stuck.
Thanks in advance.
It would be difficult for someone to help debug this with the limited code provided I think. Mainly because I'm not sure what your after() block looks like, the error that is being throw isn't occurring in this test, it's occurring in the teardown code when body.success doesn't exist (what results in body.success existing?). Additionally eyesOpen and eyesCheckWindow and eyesClose seem to be custom commands specific to Applitools, I'd at least recommend adding that as a tag or edit your post to include that information because that isn't part of the general testers' Cypress workflow/plugin stack.
Other than that, I'd try adding cy.log(body.error) or console.log(body.error) or adding the after() block, and add the results to your question.
On a separate note, you can try using the Applitools example test structure
it('works', () => {
cy.visit('https://applitools.com/helloworld');
cy.eyesOpen({
appName: 'Hello World!',
testName: 'My first JavaScript test!',
browser: { width: 800, height: 600 },
});
cy.eyesCheckWindow('Main Page');
cy.get('button').click();
cy.eyesCheckWindow('Click!');
cy.eyesClose();
});
});
or their "best practice" example structure
describe('Hello world', () => {
beforeEach(() => {
cy.eyesOpen({
appName: 'Hello World!',
browser: { width: 800, height: 600 },
});
});
afterEach(() => {
cy.eyesClose();
});
it('My first JavaScript test!', () => {
cy.visit('https://applitools.com/helloworld');
cy.eyesCheckWindow('Main Page');
cy.get('button').click();
cy.eyesCheckWindow('Click!');
});
});
Both look like they're passing text into eyesCheckWindow but I also am not familiar with applitools so this could be useless information.

Unable to get when user dennied activating location - React Native Geolocation Service

I am opening this question and answering it myself to help other users that face the same issue.
Working with a React Native app in Android that uses the package react-native-geolocation-service, when trying to get the user to activate its location (not to allow it, to activate it), I found that the button cancel wasn't returning any errors. Here is the pop up I'm talking about:
The function I was using was the following:
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
(error) => {
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
});
I was completely sure it was correct, because it was a copy from github's repo. But then, the console never logged the error.
If you are facing the same issue, check the answer below.
Turns out, the problem was that a combination of Visual Studio Code pluggins (Prettier and ESLint probably) messed up with my code. The correct code should look like this:
Geolocation.getCurrentPosition(
pos => {
// Do somehting if location activated
},
error => {
console.log(error.code, error.message);
},
{enableHighAccuracy: false, timeout: 15000, maximumAge: 10000}
);
As you can see, all of my previous code was inside the "pos" brackets, meaning that it was only entering if it was successfull. Since the error block could never get reached, I wasn't able to get the negative answer from the user.
Hope this was of use to anyone.

Stripe redirectToCheckout method redirects to successful url before showing any response in the .then section

I am trying to run a piece of code in the .then section of stripe.redirectTocheckout function. But it redirects me to the successfulUrl part before showing any response/result in the .then({}) and hence the code in the .then section does not run. Kindly help me. I am stuck here from a long time. Thank you.
stripe.redirectToCheckout({
items: [{ sku: 'abcssdd', quantity: 1 }],
successUrl:'https://your-website.com/congratulation',
cancelUrl: 'https://your-website.com/canceled',
})
.then(function (result) {
if (result.error) {
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
console.log("Inside Then");
})
The then option is there in case it fails. If it's not failing, there is no reason to show error.
It's a little confusing, IMHO, because then() is usually associated with success and catch() with the error., but note the comments form their docs below:
const stripe = Stripe('pk_test_TYauvdEDq54NiTpjx');
stripe.redirectToCheckout({
items: [
// Replace with the ID of your SKU
{sku: 'sku_123', quantity: 1}
],
successUrl: 'https://your-website.com/success',
cancelUrl: 'https://your-website.com/canceled',
}).then(({error}) => {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `error.message`.
});
src: https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout

questions about gulp recipe for browserify

The gulp recipes on github specifically says to use stackexchange for questions instead of bug reports, that's why I am here.
I am looking at the Browserify + Globs recipe, and I have some questions.
Question: what app.js?
bundledStream
// turns the output bundle stream into a stream containing
// the normal attributes gulp plugins expect.
.pipe(source('app.js'))
// the rest of the gulp task, as you would normally write it.
// here we're copying from the Browserify + Uglify2 recipe.
.pipe(buffer())
The example specifically is about using globs to match multiple files. Why do they specify a single app.js file? Do I need to actually have some app.js somewhere, and if so, what should be in it?
Question: is there an alternate form for this?
globby(['./entries/*.js']).then(function(entries) {
// create the Browserify instance.
var b = browserify({
entries: entries,
debug: true,
transform: [reactify]
});
the whole reason I am looking at this recipe is because I was using gulp-browserify, but it is unmaintained and doesn't have browserify(...).transform(), and I need to transform with babelify with presets: es2016, es2015. And it turns out, you can't just do the obvious thing: transform: [babelify, {presets: ['es2015','es2016']}], because this doesn't work.
Likewise, you can't just rely on the .babelrc file and a plain transform: [babelify], because that doesn't work (I see imports are working, but destructured parameters like constructor({val_a=1, val_b}) do not).
Overall, I want to convert this working task:
return gulp.src(['dev/scripts/**/*.js', '!dev/scripts/vendor/**/*.js'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(browserify())
.pipe(gulp.dest('build/scripts'))
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('build/scripts'))
.pipe(reload({ stream: true }))
to one that uses regular browserify, and babelify with .transform("babelify", {presets: ["es2016"]})
So it turns out the form you need is babelify.configure({})
My task is working in this form:
gulp.task('scripts', function () {
let scripts = ['dev/scripts/**/*.js', '!dev/scripts/vendor/**/*.js']
let bundledStream = through()
bundledStream
.pipe(source('main.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(plumber({
handleError: function (err) {
console.log(err)
this.emit('end')
}
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/scripts'))
.pipe(reload({ stream: true }))
globby(scripts).then(function(entries) {
let b = browserify({
entries: entries,
debug: true,
transform: [babelify.configure({
presets: ["es2016", "es2015"]
})]
})
b.bundle().pipe(bundledStream)
}).catch(function(err) {
bundledStream.emit('error', err)
})
return bundledStream
})

Hapi reply file

This code doesn't work in version 9.0.3:
server.route({
method: 'GET',
path: '/',
handler: function() {
file: 'templates/index.html'
}
});
Error:
de_modules/hapi/node_modules/hoek/lib/index.js:723
throw new Error(msgs.join(' ') || 'Unknown error');
^
Error: Unknown handler: file
In version 8 it worked well.
I've resolved the problem. From last versions this possiblity was cutted away. After I include "inert" module and registered it, that works fine.
not quite sure why at the moment, but the structure of the call has changed a bit. This worked for me.
handler: function(request, reply){
reply.file('/template/index.html');
}
found it here http://hapijs.com/tutorials/serving-files
If you have vision and inert in your package.json, you need to register them as a plugin.
server.register([require('vision'), require('inert')], function (err) {
if (err) console.log(err);
});