Saving an image file with Node.js request library causes exception - image

This is from the request's Github repo - https://github.com/mikeal/request
You can stream any response to a file stream.
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
I have modified it like so, where largeImage is a absolute url path from 3rd-party website.
request(largeImage).pipe(fs.createWriteStream('./img/large/demo.jpg'));
But I get the following error (not sure why?). I have looked at the createWriteStream API and it seems to be correct. If I only include "demo.jpg" it works fine. But if I include path next to "demo.jpg" it throws an exception.
stream.js:81
throw er; // Unhandled stream error in pipe.
^
Error: ENOENT, open './img/large/demo.jpg'
10 Oct 16:51:02 - [nodemon] app crashed - waiting for file changes before starting...
UPDATE: The problem was I didn't include ./public/ folder before the /img/.
This updated code works correctly:
request(largeImage).pipe(fs.createWriteStream('./public/img/large/demo.jpg'));

It all looks OK. My guess is that the issue is related to permissions or maybe needing to create the ./img/large directory first.
Do something like this to get more info:
var ws = fs.createWriteStream('./img/large/demo.jpg');
ws.on('error', function(err) { console.log(err); });
request(largeImage).pipe(ws);

Related

How to get a more relevant stacktrace (file name and line number) for hhvm fatal error?

I have a legacy hhvm restful api.
I made some changes to its code base and now my local server throws:
Syntax only allowed in Hack files (<?hh) or with -v
Eval.EnableHipHopSyntax=true
My current hhvm specific setting inside my php.ini is:
; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false
date.timezone="Europe/Berlin"
hhvm.libxml.ext_entity_whitelist = file,http
I checked the log at
cat /var/log/hhvm/error.log
Yet it is empty.
I do not want to allow hack file syntax but I do want more relevant information on where the error is occurring.
I want to at least know in which file I created the error. Nice to have would be in which line and at which character position within that line occurs. The api is internal, so I do not mind to expose that information for now.
Right now I am going through the git diff, and that is not a very effective way of finding the offending code.
This won't expose the error to the server response but check your sandbox settings.
The error log may be in your hhvm sandbox, not inside the main hhvm folder:
/var/log/hhvm/sandbox/error.log
There you will find the relevant information with the error's context:
[Mon May 13 15:40:32 2019] [hphp] [25:7fe693fff700:413:000001] [] \nFatal error: Syntax only allowed in Hack files (<?hh) or with -v Eval.EnableHipHopSyntax=true in /var/www/service/src/Dreamlines/BookingService/Bundle/OperatorBundle/Soap/Call/CallBuilderFactory.php on line 177

PhoneGap Build: Error: NOT_FOUND_ERR (missing files)

When I try to use my app from PhoneGap Build, it seems to be missing images. When I check in the Chrome web inspector, it's also missing script files. Here are the errors:
cordova.js:314 Uncaught Error: NOT_FOUND_ERR
at fileService.js:77
at fail (FileEntry.js:88)
at Object.callbackFromNative (cordova.js:295)
at <anonymous>:1:9
cordova.js:312 Error in Error callbackId: File410316782 : Error: NOT_FOUND_ERR
cordova.js:314 Uncaught Error: NOT_FOUND_ERR
at fileService.js:77
at fail (FileEntry.js:88)
at Object.callbackFromNative (cordova.js:295)
at <anonymous>:1:9
.png:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
I know I didn't fail to include this file, because it was working before.
Most issues like this, as well as "Upload Error [2]", can be solved in PhoneGap Build by deleting the app and re-uploading. Don't worry about losing anything, since all of your settings are in your config files. It seems that PhoneGap has a tendency to inadvertently retain or misplace files.
I tend to just delete my app and re-upload every time I need to run a build, so I don't have to waste time installing and opening the app, only to find out it's missing files.

PhantomJS failing on remote ajax field check

I developed a script to complete & submit a remote form via PhantomJS (version 2.1). For testing I built a local approximation of the remote form which included an ajax field check upon input (so, you enter an email address in the email field, and after a second it checks to see if it's a valid input). My phantom script fills out the fields, waits a few seconds for an error to be thrown, and then carries on to submit the form if everything looks okay. This all worked just fine with everything running on localhost.
However, as soon as I switch to making the call to the remote webpage (which is a third-party site; I have no access to make changes to it), it fails when the remote page performs the ajax check on fields. I have the following onResourceError function:
page.onResourceError = function(resourceError) {
system.stderr.writeLine('= onResourceError()');
system.stderr.writeLine(' - unable to load url: "' + resourceError.url + '"');
system.stderr.writeLine(' - error code: ' + resourceError.errorCode + ', description: ' + resourceError.errorString );
};
...and if I run the following line (in a Windows command prompt):
phantomjs.exe form-process.js "https://contact.site.com/auth/form?params=that&are=always&the=same" "clarence#email.com"
I get the following error:
https://contact.site.com/ajax/email-check?email=clarence#email.com"
- error code: 302,
- description: Error downloading "https://contact.site.com/ajax/email-check?email=clarence#email.com"
- server replied: Bad request
I am running this from a local environment but with no SSL certificate installed, so I assumed (based on the description of the 302 error code: the requested operation is invalid for this protocol) that it was a cross-protocol issue. But running the phantomJS line with any combination of --ssl-protocol=any, --ignore-ssl-errors=yes or --web-security=false yields the same results.
I may be misunderstanding these modes for phantomJS, but I assumed that --ssl-protocol=any would dismiss this issue, but would I still need to have a local SSL cert to get this to work? Or is there another issue here?

Error: EACCES, unlink...

I'm trying to get my meteor app up and running, but I don't understand the error that its throwing at all, which is:
/Users/ten3/.meteor/packages/meteor- tool/.1.1.10.1b51q9m++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:278
throw(ex);
^
Error: EACCES, unlink '/Users/ten3/Desktop/git/ten/website/prospect-recovery/prospect-recovery/.meteor/local/db/mongod.lock'
at Object.Future.wait (/Users/ten3/.meteor/packages/meteor-tool/.1.1.10.1b51q9m++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:398:15)
at /tools/fs/files.js:1331:28
at Object.wrapper [as unlink] (/tools/fs/files.js:1334:20)
at findMongoAndKillItDead (/tools/runners/run-mongo.js:318:11)
at launchOneMongoAndWaitForReadyForInitiate (/tools/runners/run-mongo.js:400:7)
at launchMongo (/tools/runners/run-mongo.js:656:7)
at [object Object]._.extend._startOrRestart (/tools/runners/run-mongo.js:756:19)
at [object Object]._.extend.start (/tools/runners/run-mongo.js:714:10)
at /tools/runners/run-all.js:168:26
- - - - -
I'm running a shell script before I try to run a local copy of my meteor app. It supposed to stop my application from interacting with other APIs. When I run the script (I'm on a mac) through my terminal, it returns '0' which as I read means that there are zero errors. I know that the error message is guiding me to certain lines of code, but I don't understand why I would change them if my co-worker could get his copy up and running. He is running his application on a windows computer. Thank you. I'm pretty new to this.
It was a permission error just as #thatgibbyguy first suggested. I was able to run it buy using sudo meteor to override the permission restrictions. I wasn't about to remove my mongod.lock file since that my coworker had the file and was able to get it up and running.

After porting some php and web app related files from my friend's windows computer to my mac I'm getting some errors

This is for a facebook app being run on heroku, but heroku is probably not the issue. The issue is either some kind of cache related thing, os porting, or I'm thinking it might be a carriage return issue.
In any case I'm getting a couple errors at the top and bottom respectively:
Warning: Unknown:
Warning: session_start(): open(C:\ProgramData\Jcx.Software\VS.Php\2.10.6970.0\temp/sess_i4ood4poc11ebsgth000g1nm74, O_RDWR) failed: No such file or directory (2) in /app/www/sdk/src/facebook.php on line 37
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /app/www/sdk/src/facebook.php:37) in /app/www/sdk/src/facebook.php on line 37
open(C:\ProgramData\Jcx.Software\VS.Php\2.10.6970.0\temp/sess_i4ood4poc11ebsgth000g1nm74, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\ProgramData\Jcx.Software\VS.Php\2.10.6970.0\temp) in Unknown on line 0
Essentially I have tried the whole "making sure session is at the top thing," but I don't have that session piece of code in any of the files. I have tried the whole making sure "?>" is on a new line as well to no effect.
update
I have discovered something called:
zend_extension_ts="C:\Program Files (x86)\Jcx.Software\VS.Php\2010\php 5.2\ext\php_xdebug.dll"
within a file called php.ini which even after I tried to get rid of didn't seem to change anything. So, I'm thinking this has something to do with some previous files that I pushed and then removed with extensions like puo, intellisense.cache, projphp, etc.
I don't know if those are auto-generated or not, but in any case according to my errors:
There is some session data in a file called temp. I have no file named temp.
zend_extension_ts supposedly gets referenced somewhere, but it isn't visible in my code.
I apparently need to resend session cache limiter again through session_start() which is not visible in my code.
Is not the session , I'm sure. But there is directory path included in your code but that directory does not exist! Just refactor that part of the code first!
As a tip you should use realpath() and check if path exist before attempting to use it.
Hope this helps!

Resources