adobe-photoshop / generator-core

Core Node.js library for Adobe Photoshop CC's Generator extensibility layer
MIT License
692 stars 97 forks source link

useFlite set to true causes exception when saving Pixmaps #389

Closed pixels4nickels closed 7 years ago

pixels4nickels commented 7 years ago

About 9 weeks ago I filed an issue about the streamPixmap function blowing up due to a missing the logger argument. I still cannot find the commit which added the logger argument. But in my logs I still get: Uncaught exception on Thu Jul 20 2017 15:29:12 GMT-0700 (PDT): Error trace: TypeError: Cannot read property 'log' of undefined at streamPixmap (/Applications/Adobe Photoshop CC 2017/Adobe Photoshop CC 2017.app/Contents/Required/Generator-builtin/lib/convert.js:229:19) at Object.savePixmap (/Applications/Adobe Photoshop CC 2017/Adobe Photoshop CC 2017.app/Contents/Required/Generator-builtin/lib/convert.js:276:16) at Generator.savePixmap (/Applications/Adobe Photoshop CC 2017/Adobe Photoshop CC 2017.app/Contents/Required/Generator-builtin/lib/generator.js:1610:24) at /Applications/Adobe Photoshop CC 2017/Plug-ins/Generator/lsr-generator/png_generator.js:217:28 at /Applications/Adobe Photoshop CC 2017/Plug-ins/Generator/lsr-generator/node_modules/fs-extra/lib/mkdir.js:28:14 at FSReqWrap.oncomplete (evalmachine.<anonymous>:82:15) This was happening because the logger function argument was missing but there was usage of it at line 229 Convert.js. If you set useFlite to true then you enter into that condition, which causes the exception. I now see that the code has the logger argument yet I am still getting this error.

It almost feels like the old code is still running somewhere because I cannot see how it can be undefined now. Current Convert.js is function streamPixmap(binaryPaths, pixmap, outputStream, settings, logger) {

Back when I originally encountered this bug it read: function streamPixmap(binaryPaths, pixmap, outputStream, settings) {

It almost feels like the internal Generator is keeping the old files cached or something? Really odd stuff. Thanks for any guidance in clearing the internal Generator node cache.

pixels4nickels commented 7 years ago

https://github.com/adobe-photoshop/generator-core/issues/380

pixels4nickels commented 7 years ago

Okay I see why this *seems to be happening still. It actually is a different reason that can cause the exact same exception. So the savePixmap call is not passing the logger argument, which (if you useFlite) will cause the logging statement on 229 to fail.

`function savePixmap(binaryPaths, pixmap, path, settings) { var fs = require("fs");

    // Open a stream to the output file.
    var fileStream = fs.createWriteStream(path);

    // Stream the pixmap into the file and resolve with path when successful.
    return streamPixmap(binaryPaths, pixmap, fileStream, settings)
        .thenResolve(path)
        .catch(function (err) {
            // If an error occurred, clean up the file.
            try {
                fileStream.close();
            } catch (e) {
                console.error("Error when closing file stream", e);
            }
            try {
                if (fs.existsSync(path)) {
                    fs.unlinkSync(path);
                }
            } catch (e) {
                console.error("Error when deleting file", path, e);
            }

            // Propagate the error.
            throw err;
        });
}`
pixels4nickels commented 7 years ago

The streamPixmap expects the logger instance: function streamPixmap(binaryPaths, pixmap, outputStream, settings, logger) {

pixels4nickels commented 7 years ago

As you can see, 3.8.4 still contains this issue: https://github.com/adobe-photoshop/generator-core/blob/v3.8.4/lib/convert.js

pixels4nickels commented 7 years ago

Changing line 218 from: function streamPixmap(binaryPaths, pixmap, outputStream, settings, logger) { to: function streamPixmap(binaryPaths, pixmap, outputStream, settings) {

And changing line 229 from: logger.log("Using Flite for image encoding" + (pixmap.iccProfile ? " with icc profile" : ""));

to: console.log("Using Flite for image encoding" + (pixmap.iccProfile ? " with icc profile" : ""));

Fixes the issue.

mcilroyc commented 7 years ago

I created a PR (#393) that I believe addresses this issue in a slightly better way than #390. @pixels4nickels please let me know if you agree.

pixels4nickels commented 7 years ago

If you want to pass the logger around, sure. More than anything I would love to see some tests being run since this issue would have never made it out into the wild if folks had at minimum "hand-tested" the feature. I am concerned about the brittleness of the access and saving of profiles to image headers. Thanks for your attention to this.

pixels4nickels commented 7 years ago

Apologies, I now see some tests when running locally. It would be great to get the flite usage in there.

mcilroyc commented 7 years ago

Regarding tests: Our most comprehensive set of tests exercises the generator-assets plugin which no longer calls savePixmap (it uses streamPixmap directly). This is not an excuse, but an explanation at least.

pixels4nickels commented 7 years ago

Thanks for the explanation, Cory. I appreciate your attention on getting these issues worked out. I am now saving pixmaps with P3 profiles.

Best, Ken

On Tue, Jul 25, 2017 at 8:32 AM, Cory McIlroy notifications@github.com wrote:

Regarding tests: Our most comprehensive set of tests exercises the generator-assets plugin which no longer calls savePixmap (it uses streamPixmap directly). This is not an excuse, but an explanation at least.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adobe-photoshop/generator-core/issues/389#issuecomment-317775379, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHAazPGnQJHeONh-eIq80yQ3fcoRC_pks5sRgp1gaJpZM4OewIK .

pixels4nickels commented 7 years ago

BTW, are you saying if I saved my pixmaps using streamPixmap that I would not be blocked by the missing logger argument issue? If so, could you point me to some code in the test plugin that shows how to implement streamPixmap?

That would be incredibly helpful

-Ken

On Tue, Jul 25, 2017 at 9:54 AM, Ken Rogers krflash@gmail.com wrote:

Thanks for the explanation, Cory. I appreciate your attention on getting these issues worked out. I am now saving pixmaps with P3 profiles.

Best, Ken

On Tue, Jul 25, 2017 at 8:32 AM, Cory McIlroy notifications@github.com wrote:

Regarding tests: Our most comprehensive set of tests exercises the generator-assets plugin which no longer calls savePixmap (it uses streamPixmap directly). This is not an excuse, but an explanation at least.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adobe-photoshop/generator-core/issues/389#issuecomment-317775379, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHAazPGnQJHeONh-eIq80yQ3fcoRC_pks5sRgp1gaJpZM4OewIK .

mcilroyc commented 7 years ago

@pixels4nickels I think what you're looking for can be followed backwards from here https://github.com/adobe-photoshop/generator-assets/blob/master/lib/renderer.js#L1452

mcilroyc commented 7 years ago

fix included in Photoshop 2018